Coder Social home page Coder Social logo

carouselnotificationexample's People

Contributors

ahmettkeskin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

mohsinalimat

carouselnotificationexample's Issues

Navigation to next/previous image breaks in iOS 14

I have recently started building my own iOS app and trying to add Push Notifications particularly the Rich Push notifications.

I tried to use this example to show Carousel in Push Notification exactly as used in this project, it seems the Scrolling to next item is breaking in iOS 14.

I can see the scrollNextItem/scrollPreviousItem from the example are getting called but UICollectionView doesn't scroll to next/previous image using debugger.

Tested this with iOS 14.0.1 where the scroll to next/prev doesn't work, whereas this works fine with iOS 13.6.

Tried to add the UIPageControl and see if the scrolling works with ScrollView, but I couldn't see the PageControl itself in the UI.

var xPos: CGFloat
var yPos: CGFloat
let height: CGFloat = 30
let pageControl = UIPageControl()
pageControl.addTarget(self, action: #selector(self?.changePage(sender:)), for: .touchUpInside)
pageControl.hidesForSinglePage = true
pageControl.numberOfPages = 4
pageControl.currentPage = 0
xPos = (self.view.frame.width - width) / 2
yPos = (self.view.frame.height - height) - 10
pageControl.frame = CGRect(x: xPos, y: yPos, width: width, height: height)
self?.pageControl?.removeFromSuperview()
self?.pageControl = pageControl
Following are the attributes that I have for this view.

UIScrollView Attributes

And then using the scrollViewDidEndDecelerating delegate method.

func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
    pageControl?.currentPage = Int(scrollView.contentOffset.x) / Int(scrollView.frame.width)
    currentIndex = pageControl?.currentPage ?? 0
}

Changing based on the user action in func didReceive(_ response: UNNotificationResponse, completionHandler completion: @escaping (UNNotificationContentExtensionResponseOption) -> Void)

if response.actionIdentifier == "carousel.next" {
    if ((self.pageControl?.currentPage ?? 0) + 1) <  4) {
        self.pageControl?.currentPage += 1
        changePage(sender: self.pageControl)
    }
} else if response.actionIdentifier == "carousel.previous" {
    if ((self.pageControl?.currentPage ?? 0) - 1) <  4) {
        self.pageControl?.currentPage -= 1
        changePage(sender: self.pageControl)
    }
}

func changePage(sender: UIPageControl) {
    let pageCount = datahandler.carousalInfo?.data?.count ?? 0
    guard pageCount > 1 else {
        return
    }
    if sender.currentPage != currentIndex {
        currentIndex = sender.currentPage
        let indexPath = IndexPath(item: currentIndex, section: 0)
        self.carousalCollection?.scrollToItem(at: indexPath, at: .centeredHorizontally, animated: true)
    }
}

Posted the same in SO here
Please help me figure out if something has changed in iOS 14 related to UICollectionView

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.