davdroman / swiftui-navigation-transitions Goto Github PK
View Code? Open in Web Editor NEWPure SwiftUI Navigation transitions ✨
License: MIT License
Pure SwiftUI Navigation transitions ✨
License: MIT License
I wanted to get the library out asap so I didn't have time to generate DocC, but now that it's out this should be my next task.
i was wondering if there is a way to create a (custom) transition that does nothing. i.e. immediately jumps from one view to the next.
for transitioning between two views this appearance can be achieved by clearing and immediately setting the navigation path.
but for the transition from an empty path to a single element or from a single element to to an empty path the default transition is always used.
thanks
andre
hello, i want to show view like present full screen view animation
i tried slide(axis: .vertical)) but animation not like present
Hi @davdroman, thanks so much for making this library.
Recently, I bumped into a strange issue which is 100% reproducible on iOS 17 device (not simulator)
Reproducible setup within Demo app
default
transition and pan
interactive gesturePageOne
has navigation bar visible, while PageTwo
has navigation bar hiddenReproduce steps
From PageOne
, go to PageTwo
then using pan gesture to go back to PageOne
, then tap Show me!
button again.
The UI will hang forever
You can check out my branch for the demo: https://github.com/muzix/swiftui-navigation-transitions/tree/muzix/freezing-issue-ios-17
Investigating
I think this is a SwiftUI bug. But I found that adding setNavigationBarHidden(false, animated: true|false)
into NavigationTransitionDelegate
somehow fixed this issue.
func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
navigationController.setNavigationBarHidden(false, animated: true)
initialAreAnimationsEnabled = UIView.areAnimationsEnabled
UIView.setAnimationsEnabled(transition.animation != nil)
baseDelegate?.navigationController?(navigationController, willShow: viewController, animated: animated)
}
But it has another side effect which make navigation bar blinking when transitioning between screens with hidden nav bar.
Hi,
I'm using it and it works fine, except 1 problem:
I want to use default transition for subview transition
What i do:
NavigationStack(path: $path) {
...
.navigationDestination(for: MediaItemInfo.self) { item in
...
}
.navigationStackTransition(
.slide(axis: .vertical).animation(.linear(duration: 0.5))
)
Later, in the new view, i need the default transition for all subviews
NavigationLink(destination: ...) {
}
.navigationStackTransition(.default)
What is strange, is the transition are still the .slide one, but when i pop the new view, i have the standard transition.
What i'm missing ? Thanks
thank you for creating this library @davdroman!
I have a global background color in my app (implemented using the ZStack approach). How do I change the fade transition to have the same color?
notice how the background changes to white (black if dark mode) during the fade transition.
Would it be possible to add a slide-inverse animation also? I mean in a ltr application from left to right or if you prefer from leading to trailing.
It would be a convenient feature to have out of the box.
It's really fast to code too, I made it in my project like this:
import AtomicTransition
import SwiftUI
import NavigationTransitions
extension AnyNavigationTransition {
/// A transition that moves both views in and out along the specified axis.
///
/// This transition:
/// - Pushes views left-to-right and pops views left-to-right when `axis` is `horizontal`.
/// - Pushes views top-to-bottom and pops views top-to-bottom when `axis` is `vertical`.
public static func inverseSlide(axis: Axis) -> Self {
.init(InverseSlide(axis: axis))
}
}
extension AnyNavigationTransition {
/// Equivalent to `slide(axis: .horizontal)`.
@inlinable
public static var slide: Self {
.inverseSlide(axis: .horizontal)
}
}
/// A transition that moves both views in and out along the specified axis.
///
/// This transition:
/// - Pushes views left-to-right and pops views left-to-right when `axis` is `horizontal`.
/// - Pushes views top-to-bottom and pops views top-to-bottom when `axis` is `vertical`.
public struct InverseSlide: NavigationTransition {
private let axis: Axis
public init(axis: Axis) {
self.axis = axis
}
/// Equivalent to `Move(axis: .horizontal)`.
@inlinable
public init() {
self.init(axis: .horizontal)
}
public var body: some NavigationTransition {
switch axis {
case .horizontal:
MirrorPush {
OnInsertion {
Move(edge: .leading)
}
OnRemoval {
Move(edge: .trailing)
}
}
case .vertical:
MirrorPush {
OnInsertion {
Move(edge: .top)
}
OnRemoval {
Move(edge: .bottom)
}
}
}
}
}
extension InverseSlide: Hashable {}
Only with the last update 0.10.0 my app works good when build, but when archive to submit to Appstore I got error (Command SwiftCompile failed with a nonzero exit code)
6. While evaluating request QualifiedLookupRequest(0x12dd764b0 StructDecl name=NotionAppsView, {Apps.(file).NotionAppsView@/Users/itarek/Library/Mobile Documents/NotionAppsView.swift:14:8}, 'Body', { NL_ProtocolMembers, NL_RemoveNonVisible, NL_RemoveOverridden, NL_OnlyTypes })
7. While evaluating request DirectLookupRequest(directly looking up 'Body' on SwiftUI.(file).View with options { })
8. While loading members for extension of View (in module 'NavigationTransitions')
9. While deserializing 'navigationTransition' (FuncDecl @ 392035) in 'NavigationTransitions'
10. ...decl is named 'navigationTransition(_:interactivity:)'
11. While deserializing '_' (OpaqueTypeDecl @ 374635) in 'NavigationTransitions'
12. *** DESERIALIZATION FAILURE ***
*** If any module named here was modified in the SDK, please delete the ***
*** new swiftmodule files from the SDK and keep only swiftinterfaces. ***
module 'NavigationTransitions', builder version '5.8.1(5.8.1)/Apple Swift version 5.8.1 (swiftlang-5.8.0.124.5 clang-1403.0.22.11.100)', built from source, non-resilient, loaded from '/Users/itarek/Library/Developer/Xcode/DerivedData/BuildProductsPath/Release-iphoneos/NavigationTransitions.swiftmodule/arm64-apple-ios.swiftmodule'
module with extension is not loaded (SwiftUIIntrospect)
If i switch back to version [0.9.3] everything works again.
Can you help?
As in title, is there macOS support planned at least in the future?
Apple will require Xcode 15/Swift 5.9 to deploy apps to the App Store by April 2024. So at some point then I'll bump min Swift version to 5.9. This is just an issue to remind me of it.
Branch: https://github.com/davdroman/swiftui-navigation-transitions/tree/swift-5.9
Originally posted by izombieprod December 19, 2023
Every time after building the application, the first transition is the default slide every time. Your animation is applied only after you call those views one time with default transition animation. Do you know what I'm doing wrong?
A bit of an unknown for me as I've never really worked with the 3D transform APIs, but good to explore nonetheless.
My code is:
@State var enableInteractivity = false
NavigationStack(path: $stack) {
...
}
.navigationTransition(.default, interactivity: enableInteractivity ? .edgePan : .disabled)
I change enableInteractivity
flag in the onAppear { }
of views in the NavigationStack, however, it doesn't work on iOS 16 and iOS 17 - the initial value of enableInteractivity
is always used.
Might be helpful to have in addition to BringToFront
/SendToBack
.
Can be reproduced in iOS 17 using Xcode 15. Not sure about other versions.
I have a NavigationStack inside a sheet.
Inside that NavigationStack, I navigate to a destination using the following transition:
.navigationTransition(.fade)
If I reproduce the following behaviors:
The navigation bar will be hidden.
I was wondering if there is a workaround to fix this, or if a fix could be introduced for this.
Many thanks!
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.