Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Standard animation not working while using Loop #302

Open
ghost opened this issue Oct 7, 2022 · 4 comments
Open

[BUG] Standard animation not working while using Loop #302

ghost opened this issue Oct 7, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@ghost
Copy link

ghost commented Oct 7, 2022

Describe the bug
While using Loop the standard animation is not working properly.
If I add a data from view its working fine but when i try to use data from viewmodel then its not woking properly

To Reproduce
Add a data from ViewModel and add a loopPages()

  • Sample code
@ObservedObject var discoverVM: DiscoveryViewModel
var body: some View {
 Pager(page: .first(), data: discoverVM.showProfiles, id: \.self) {
                    self.pageView($0.connections ?? 0)
                }
                .pagingPriority(.simultaneous)
                .draggingAnimation(.standard)
                .loopPages()
                .sensitivity(.high)
                .itemSpacing(10)
                .itemAspectRatio(1.3, alignment: .start)
                .padding(20)
}

Expected behavior
I want standard animation with using loopPages()

Screenshots / Videos
If applicable, add screenshots to help explain your problem.
https://user-images.githubusercontent.com/80446711/194536499-8c02f913-72f0-46f8-9832-8708cc212e45.MP4

Environment:
Xcode : 14.1
iOS: 15.5

  • OSX: [iOS]
  • Device [iPhoneXs Max]
  • SwiftUIPager version [2.4.0]

Additional context
Add any other context about the problem here.

@ghost ghost added the bug Something isn't working label Oct 7, 2022
@ghost ghost changed the title [BUG] [BUG] Animation not working while using Loop Oct 8, 2022
@ghost ghost changed the title [BUG] Animation not working while using Loop [BUG] Standard Animation not working while using Loop Oct 8, 2022
@ghost ghost changed the title [BUG] Standard Animation not working while using Loop [BUG] Standard animation not working while using Loop Oct 8, 2022
@dmikots
Copy link

dmikots commented Oct 28, 2022

same problem

@ikhaled-ali
Copy link

ikhaled-ali commented Jun 11, 2023

Hi @smallworldpc , @dmikots

I fixed this issue by doing a small trick
may helps someone later 😌✌🏼

The problem that the Pager needs at least 5 elements to work as expected (don't ask me why 👀)

My trick is to repeat data if it has count < 5:

        private func fixBanners(_ array: [YourModelItem]) -> [YourModelItem]{
        if array.count > 1 && array.count < 5 {
            let originalCount = array.count
            let expectedCount = 5
            let remaingCount = expectedCount - originalCount
            let targetCount = originalCount * ( remaingCount == 1 ? remaingCount + 1 : remaingCount )
            let repeatCount = max(1, targetCount / originalCount)
            
            var repeatedArray = Array(repeating: array, count: repeatCount).flatMap { $0 }
            let remainingCount = targetCount - repeatedArray.count
            
            if remainingCount > 0 {
                repeatedArray += array.prefix(remainingCount)
            }
            
            
/** Important for identifiable models: change object identifier **/
repeatedArray = repeatedArray.map { object in
                var newObj = object
                newObj.id = UUID()
                return newObj
            }
            return repeatedArray
        }else{
            return array
        }
    }

@fermoya
Copy link
Owner

fermoya commented Jun 11, 2023

@ikhaled-ali doesn't it work if you use loopPages(repeating: 2)?

@ikhaled-ali
Copy link

@ikhaled-ali doesn't it work if you use loopPages(repeating: 2)?

Unfortunately no 😞, the transition looks like the next page comes from behind the current one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants