All Projects → Amzd → ResponderChain

Amzd / ResponderChain

Licence: MIT license
Cross-platform first responder handling without subclassing views or making custom ViewRepresentables in SwiftUI. Similar to FocusState but for iOS 13+

Programming Languages

swift
15916 projects
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to ResponderChain

SwiftUI-Color-Kit
SwiftUI Color Pickers, Gradient Pickers And All The Utilities Needed To Make Your Own!
Stars: ✭ 120 (+73.91%)
Mutual labels:  swift-package-manager, swiftui
Shift
Light-weight EventKit wrapper.
Stars: ✭ 31 (-55.07%)
Mutual labels:  swift-package-manager, swiftui
ScrollViewProxy
ScrollViewProxy for SwiftUI on iOS 13 and up
Stars: ✭ 135 (+95.65%)
Mutual labels:  swift-package-manager, swiftui
ConsoleUI
Rasterize SwiftUI views to images from macOS terminal
Stars: ✭ 52 (-24.64%)
Mutual labels:  swift-package-manager, swiftui
CurrencyText
Currency text field formatter available for UIKit and SwiftUI 💶✏️
Stars: ✭ 124 (+79.71%)
Mutual labels:  swift-package-manager, swiftui
swift-composable-app-example
Example iOS app built with module composition in mind.
Stars: ✭ 79 (+14.49%)
Mutual labels:  swift-package-manager, swiftui
SwiftUI-Shapes
Commonly Used Shapes and Utilities In SwiftUI
Stars: ✭ 52 (-24.64%)
Mutual labels:  swift-package-manager, swiftui
column-text-view-ui
📄 Column Text View is an adaptive UI component that renders text in columns, horizontally [iOS 12, UIKit, TextKit, SwiftUI].
Stars: ✭ 11 (-84.06%)
Mutual labels:  swift-package-manager, swiftui
Laden
SwiftUI loading indicator view
Stars: ✭ 23 (-66.67%)
Mutual labels:  swift-package-manager, swiftui
tapit-app
App which lets two people share their social media details by simply putting one phone on top of the other ("tapping"). Currently in development by Nikita Mounier.
Stars: ✭ 18 (-73.91%)
Mutual labels:  swift-package-manager, swiftui
SwiftDown
📦 A themable markdown editor component for your SwiftUI apps.
Stars: ✭ 203 (+194.2%)
Mutual labels:  swift-package-manager, swiftui
Swiftuix
Extensions and additions to the standard SwiftUI library.
Stars: ✭ 4,087 (+5823.19%)
Mutual labels:  swift-package-manager, swiftui
SwiftCurrent
A library for managing complex workflows in Swift
Stars: ✭ 286 (+314.49%)
Mutual labels:  swift-package-manager, swiftui
ecs-demo
Minimal demo App for the Fireblade Entity-Component System (ECS)
Stars: ✭ 20 (-71.01%)
Mutual labels:  swift-package-manager
Router
Router is a library that assists with SwiftUI view transitions.
Stars: ✭ 68 (-1.45%)
Mutual labels:  swiftui
PhotoSelectAndCrop
This package integrates a UIImagePickerController into a SwiftUI app. Obtain 1) a copy of the original image, 2) a scaled and / or cropped version of it, 3) a CGFloat and 4) CGPoint. The CGFloat and CGPoint represent the scale and position of the original image used to make the processed version.
Stars: ✭ 57 (-17.39%)
Mutual labels:  swiftui
Svadilfari
Gesture Control for Safari on iOS and iPadOS
Stars: ✭ 52 (-24.64%)
Mutual labels:  swiftui
AStack
The Missing SwiftUI Adaptive and Accessible Stacks Library.
Stars: ✭ 110 (+59.42%)
Mutual labels:  swiftui
KeyboardKitPro
KeyboardKit Pro extends KeyboardKit with pro features.
Stars: ✭ 42 (-39.13%)
Mutual labels:  swiftui
Chord-Provider
A Chordpro parser/editor in SwiftUI 4 for macOS and iOS
Stars: ✭ 20 (-71.01%)
Mutual labels:  swiftui

As of June 7 2021 this functionality is in the SwiftUI 3 beta. https://developer.apple.com/documentation/SwiftUI/FocusState

The Apple implementation is a bit different from ResponderChain but switching over looks to be quite easy.

Also the Apple implementation only supports iOS 15 so I think this repo is still useful for backwards compatibility.

⛓️ ResponderChain

Cross-platform first responder handling without subclassing views or making custom ViewRepresentables in SwiftUI

Features

  • 💡 Easy to use: Get, set and resign first responder simply through an EnvironmentObject.
  • Time Saving: If an underlying view can become first responder all you have to do is tag it; and it works!
  • 👀 Insightful: Gives insight in which views can become first responder.

Overview

Attach the ResponderChain as environmentObject.

// In the SceneDelegate or ApplicationDelegate where you have access to the window:
let rootView = Example().environmentObject(ResponderChain(forWindow: window))

// SwiftUI only:
Example().withResponderChainForCurrentWindow()

Tag views that can become first responder.

TextField(...).responderTag("MyTextField")

Check tagged views that are currently available to become first responder.

chain.availableResponders.contains("MyList")

Make tagged views become first responder.

chain.firstResponder = "MyTextField"
if chain.firstResponder == nil {
    print("Failed")
}

This is completely safe, if "MyTextField" was either not available to become first responder or it wasn't tagged properly; chain.firstResponder will become nil

Resign first responder.

chain.firstResponder = nil

Note: This only works if the current firstResponder was tagged.

Example

Attach the ResponderChain as environmentObject.

...
// In the SceneDelegate or ApplicationDelegate where you have access to the window:
let rootView = ResponderChainExample().environmentObject(ResponderChain(forWindow: window))

// SwiftUI only:
ResponderChainExample().withResponderChainForCurrentWindow()
...

ResponderChainExample.swift

struct ResponderChainExample: View {
    @EnvironmentObject var chain: ResponderChain
    
    var body: some View {
        VStack(spacing: 20) {
            // Show which view is first responder
            Text("Selected field: \(chain.firstResponder?.description ?? "Nothing selected")")
            
            // Some views that can become first responder
            TextField("0", text: .constant(""), onCommit: { chain.firstResponder = "1" }).responderTag("0")
            TextField("1", text: .constant(""), onCommit: { chain.firstResponder = "2" }).responderTag("1")
            TextField("2", text: .constant(""), onCommit: { chain.firstResponder = "3" }).responderTag("2")
            TextField("3", text: .constant(""), onCommit: { chain.firstResponder = nil }).responderTag("3")
            
            // Buttons to change first responder
            HStack {
                Button("Select 0", action: { chain.firstResponder = "0" })
                Button("Select 1", action: { chain.firstResponder = "1" })
                Button("Select 2", action: { chain.firstResponder = "2" })
                Button("Select 3", action: { chain.firstResponder = "3" })
            }
        }
        .padding()
        .onAppear {
            // Set first responder on appear
            DispatchQueue.main.async {
                chain.firstResponder = "0"
            }
        }
    }
}

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].