Giter VIP home page Giter VIP logo

swiftui-stack's Introduction

stack

Custom Stack Navigation for SwiftUI

This library provides a custom container view for SwiftUI that offers an alternative to the standard NavigationStack. It aims to improve the customizability of transitions during screen navigation by moving away from the behaviors of UINavigationController and UINavigationBar.

Features

  • Customizable transitions during screen navigation
  • Contextual animations similar to iOS home screen app icons and app screens
  • Familiar API to NavigationView and NavigationStack for ease of use
  • Path support for restoring previously navigated views

Getting Started

To use this library, you'll need to work with three main symbols: Stack, StackLink, and StackUnwindLink.

Example Usage

  1. Import the SwiftUIStack module in your SwiftUI view file:
import SwiftUIStack
  1. Use the Stack container in your view hierarchy:
var body: some View {
  Stack {
    // Your views here...
  }
}
  1. Create navigation links using StackLink with your desired transition and destination:
StackLink(transition: .slide, value: someValue) {
  Text("Navigate to detail view")
}

You can also set the matched transition in the transition parameter using a unique identifier and a namespace:

StackLink(transition: .matched(identifier: user.id, in: local), value: someValue) {
  Text("Navigate to detail view with matched transition")
}
  1. Optionally, use StackUnwindLink to create a navigation link back to the previous view:
StackUnwindLink {
  Text("Back to previous view")
}

Unwind Context

In stacked views, you can access the unwindContext as an EnvironmentValue. You can pass the unwindContext to a StackUnwindLink. This allows you to explicitly specify the stack that triggers the unwind.

@Environment(\.stackUnwindContext) var unwindContext

StackUnwindLink(target: .specific(unwindContext)) {
  Text("Back to Menu")
}

StackUnwindLink Modes

StackUnwindLink now supports different modes for navigation. To navigate back to the root of the target stack, use the .all mode.

StackUnwindLink(mode: .all) {
  Text("Back to Root")
}

Nested Stacks

This technique is useful for nested stacks when you need to send a message across multiple levels of the hierarchy. By using the unwindContext in conjunction with StackUnwindLink, you can effectively communicate between nested stacks and navigate through different levels of the view hierarchy.

Installation

This library currently only supports installation via Swift Package Manager.

To add the package to your project, you can manually add it to your Package.swift file:

dependencies: [
    .package(url: "https://github.com/FluidGroup/swiftui-stack.git", from: "1.0.0")
]

Contributing

(Include instructions for contributing to the project, such as opening issues, submitting pull requests, and any other relevant information)

License

This project is licensed under the Apache License, Version 2.0. See the LICENSE file for more information.

swiftui-stack's People

Contributors

muukii avatar shima11 avatar

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.