blsage / ipages Goto Github PK
View Code? Open in Web Editor NEWQuickly implement swipable page views.
Quickly implement swipable page views.
Stack
2022-08-22 19:46:00.438076-0400 tweetmarks[43546:3140745] *** Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'child view controller:<_TtGC7SwiftUI19UIHostingControllerVS_7AnyView_: 0x11dc0e5f0> should have parent view controller:<UIPageViewController: 0x10621aa00> but requested parent is:<UIPageViewController: 0x1061fd200>'
*** First throw call stack:
(0x18a4a9288 0x1a31d8744 0x18a500390 0x18ca49dd0 0x18d1b6774 0x18d1b6958 0x18d1b6c50 0x104a95418 0x104a95530 0x1928ae4e8 0x19218a300 0x19223a704 0x192115c10 0x1920f1564 0x1920b31ac 0x1920e9bd4 0x1bca3bb18 0x1bca3b508 0x1bca3a318 0x192061124 0x192d34da8 0x192052784 0x19205e618 0x1920570f8 0x192050110 0x19204f1a4 0x192d35cb0 0x19215c798 0x19204d5b4 0x19204d640 0x19213d540 0x1b9133a10 0x19204d4d8 0x19204d7a8 0x18a4510c4 0x18a420080 0x18a41b13c 0x18a42ebc8 0x1a6599374 0x18cda2b58 0x18cb24090 0x192288f24 0x1921b6e08 0x1921980f4 0x10470c4a8 0x10470d3bc 0x105d99da4)
libc++abi: terminating with uncaught exception of type NSException
dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
*** Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'child view controller:<_TtGC7SwiftUI19UIHostingControllerVS_7AnyView_: 0x11dc0e5f0> should have parent view controller:<UIPageViewController: 0x10621aa00> but requested parent is:<UIPageViewController: 0x1061fd200>'
terminating with uncaught exception of type NSException
Hello, I'm trying to fill iPages using ForEach but I get this error. "Thread 1: Fatal error: Index out of range", on line 78 of PageViewController.swift of the iPages project.
This is the correct code to use or not support dynamic views ?
Thanks
iPages {
ForEach(notifications, id: \.self) { notification in
VStack {
Text(notification.subject)
.font(.title2)
.fontWeight(/*@START_MENU_TOKEN@*/.bold/*@END_MENU_TOKEN@*/)
Text(notification.kind)
.font(.title2)
Text(notification.updatedAt)
.font(.title3)
}
}
}
Hello!
Absolutely love the look of this but I've been struggling to get it working with custom views. I keep getting an error saying Cannot convert value of type someCustomView to closure result type '[UIViewController]'
Is there something I'm doing wrong?
Here's a screenshot of my code too:
Thanks in advance!
Hi, This is a nice package and quite easy to use.
Just encounter the issue: after putting my custom view inside an iPage view, all the child view lost the ability to react to state changes:
Example:
struct SetUpView: View {
@State var foo: String = "Hello"
var body: some View {
ZStack {
Text("\(foo)")
Button("Button") {
foo = "123"
}
}
.ignoresSafeArea(.all)
}
}
After putting this view inside iPage, when the button clicked, the text won't get changed.
iPages {
SetUpView()
}
.ignoresSafeArea(.all)
and it works normal when put outside the iPage block.
Any solution?
That's what happens when I try to scroll between several pages with selection binding:
Video:
https://streamable.com/aiva4p
Code:
struct TestView: View {
@State var selectedIdx = 0
var body: some View {
iPages(selection: $selectedIdx) {
Color.red
Color.blue
Color.yellow
}
.onChange(of: selectedIdx) { value in
print("INDEX: \(value)")
}
}
}
This is a bit of a weird one an potentially not iPages related. I'm curious if you can recreate this issue.
I was using the default apple PageTabViewStyle but saw this library and gave it a shot. My app has buttons that show up based on if statements. This worked fine with PagesTabView, but upon adding iPages, the buttons inside if statements disappear. If I remove the if statement the buttons pop back up.
Not quite sure what the issue is. I've attached my ContentView.swift file below, with most of my code removed for clarity.
`
import SwiftUI
import HealthKit
import HealthKitUI
import iPages
class SummaryHolder: ObservableObject {
@published var theSummary: HKActivitySummary = HKActivitySummary();
}
struct ContentView: View {
var body: some View {
iPages{
ZStack{
LinearGradient(gradient: Gradient(colors: [.black, Color("darkBlue")]),
startPoint: .topLeading,
endPoint: .bottomTrailing).ignoresSafeArea()
VStack {
VStack {
if movePercent >= 50 {
Button(action: /@START_MENU_TOKEN@//@Placeholder=Action@/{}/@END_MENU_TOKEN@/) {
DispenseButton(title: "One Spin",
textColor: .blue,
backgroundColor: .white)
}
}
if movePercent >= 75 {
Button(action: /*@START_MENU_TOKEN@*//*@PLACEHOLDER=Action@*/{}/*@END_MENU_TOKEN@*/) {
DispenseButton(title: "Two Spins",
textColor: .blue,
backgroundColor: .white)
}
}
if movePercent >= 100 {
Button(action: /*@START_MENU_TOKEN@*//*@PLACEHOLDER=Action@*/{}/*@END_MENU_TOKEN@*/) {
DispenseButton(title: "Three Spins",
textColor: .blue,
backgroundColor: .white)
}
}
if movePercent < 50 {
Image(systemName: "exclamationmark.triangle.fill") .renderingMode(.original)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 180, height: 180, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
Text("Get moving and try again later").font(.system(size: 20, weight: .bold, design: .default))
.foregroundColor(.white)
.padding().multilineTextAlignment(.center)
}
}
Spacer()
}
}
Text("Add Bluetooth Menu here").tabItem {
Image(systemName: (selected == 0 ? "sun.fill" : "sun"))
Text("Home")
}
}.hideDots(false).edgesIgnoringSafeArea(.all)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
Group {
ContentView()
}
}
}
`
Currently the example file adds two dependencies to every project that aren’t needed.
You should’ve created a new folder called “Example” at the root of the repo with an example Xcode project.
I get an error: Cannot find 'iPageControl' in scope when I try to compile
If you set disableBounce
to true
it's no longer possible to change the selected tab via the binding.
Edit: only the first and last tab aren't accessible via the binding. The navigation to tabs between them is still working.
Interactive example to reproduce:
struct ContentView: View {
@State var selection = 0
@State var bounceDisabled = false
var body: some View {
VStack {
Button("Tab 0", action: { selection = 0 })
Button("Tab 1", action: { selection = 1 })
Button("Toggle bounce", action: { bounceDisabled.toggle() } )
Text("Selected tab: \(selection)")
Text(bounceDisabled ? "Bounce disabled" : "Bounce enabled")
iPages(selection: $selection) {
Text("Tab 0")
Text("Tab 1")
}
.disableBounce(bounceDisabled)
}
}
}
Currently there's no Mac support (except Catalyst), it'd be great to be able to use iPages on macOS.
So, first of all, I'm a total SwiftUI beginner so bare with me.
I'm working on my first app in which I would like a page view controller that allows me to swipe between views. In my app I'm fetching calendar events which I'm accessing in my views through an observable object. The problem is that when I'm trying to access my observed object in iPages, the array is empty and I can't understand why. Here is a simplified example:
class EventsRepository: ObservableObject {
static let shared = EventsRepository()
// Code
@Published var events: [EKEvent]?
// Code
let events = self.eventStore.events(matching: predicate)
}
import iPages
struct ContentView: View {
@ObservedObject var eventsRepository = EventsRepository.shared
@State private var currentPage = 0
var body: some View {
Text(String(describing: eventsRepository.events)) // This is **not** empty
iPages(selection: $currentPage) {
Text(String(describing: eventsRepository.events)) // This **is** nil
}
}
}
If this is not a problem with iPages I would really appreciate if you could try to explain to me what I'm doing wrong.
Thanks!
the swipe back feature not implemented correctly as the background does not changes
.dotsBackgroundStyle(.prominent)
does not appear to have any effect on the view.
Hi there, thanks for the quick fix yesterday now it works like charm!
Just encounter another issue, when I change the state of iPage parents view, iPage will trigger an unwanted animation.
struct TabViewParentView: View {
@State var selectedIndex: Int = 0
@State var tabViewIsHidden: Bool = false
var body: some View {
ZStack {
iPages(selection: $selectedIndex) {
ProfileView()
SecondView()
ThirdView()
}
.hideDots(true)
VStack {
Button {
tabViewIsHidden = !tabViewIsHidden
} label: {
Text("HELLO THERE!")
}
Spacer()
Text("TEXT")
.foregroundColor(.white)
.opacity(tabViewIsHidden ? 0 : 1)
}
}
}
}
When the button pressed and @State tabViewIsHidden was changed, the iPage will scroll to the same page with animation:
I wonder if it is possible to prevent this? This is needed for making my custom tab view control, I was making an auto dismissed tab view control, but when I change the state, this unwanted animation was triggered.
I'm trying out iPages however I encountered the following issue.
It's a very basic usage - one master view initializes iPages and two subviews A and B.
MasterView.swift
import SwiftUI
import iPages
struct MasterView: View {
@State var currentPage: Int = 0
var body: some View {
iPages([SubViewA(), SubViewB()], currentPage: $currentPage)
}
}
SubViewA.swift
import SwiftUI
struct SubViewA: View {
var body: some View {
Text("this is subview A")
}
}
SubViewB.swift
import SwiftUI
struct SubViewB: View {
var body: some View {
Text("this is subview B")
}
}
The above code does not compile with the unhelpful error as follows.
Environment
XCode: Version 12.0.1
macOS: Catalina 10.15.7
Please can anyone suggest if I'm doing anything incorrect or there is a bug somewhere in the library? Thanks in advance!
Does not work with .navigationBarHidden(true)
When I try to resize windows on macOS, iPages doesn't change its width/height to match the new window size.
Sample code:
import SwiftUI
import iPages
struct ExampleApp: App {
@SceneBuilder var body: some Scene {
WindowGroup {
iPages {
Text("Hello World")
Text("Hello World")
Text("Hello World")
Text("Hello World")
}
}
}
}
Swiping is dope. Super natural spring. I really fuck with that. Similar to the other repositories, all comments here are ease of use or aesthetic related. The engine runs well!
Page number confusion. I wanted to see if currentPage
was zero indexed or 1 indexed and it wasn't in the documentation. Easy thing to add.
The app crashes when you enter a negative current page. Consider making current page an unsigned int, so change Int
to UInt
. I think that makes more sense in this context bc you could never have a negative page count.
The app crashes when you enter a non-valid current page. Thoughts on just making it instead go to the nearest page? If you enter page 9 and there are 6 pages just send it to page six.
An aesthetic point, but I did very much expect some dots at the bottom of the view. At least something to indicate the type of element I was dealing with. My first step was to I look at the init's & the modifiers to try to see if I was simply missing that option and didn't see anything.
It was really difficult to figure out the default height and width of the view. It was also difficult to figure out if that height and width was inherited from the subviews. Unsure the best way to communicate that information, but definitely confusing.
We should toss in a sexy dummy view that'd be cool.
Default colors are .white and .black.
Can set any other color (.blue, .green...) but if set .clear, the default color will be displayed.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.