{"id":18269825,"url":"https://github.com/Amzd/ResponderChain","last_synced_at":"2025-04-04T23:31:35.843Z","repository":{"id":54892685,"uuid":"319349284","full_name":"Amzd/ResponderChain","owner":"Amzd","description":"Cross-platform first responder handling without subclassing views or making custom ViewRepresentables in SwiftUI. Similar to FocusState but for iOS 13+","archived":false,"fork":false,"pushed_at":"2021-06-08T07:45:22.000Z","size":10059,"stargazers_count":74,"open_issues_count":3,"forks_count":11,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-27T19:09:05.305Z","etag":null,"topics":["cross-platform","ios","macos","responder","responder-handling","swift-package-manager","swiftui"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Amzd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["Amzd"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2020-12-07T14:42:52.000Z","updated_at":"2024-12-25T21:33:26.000Z","dependencies_parsed_at":"2022-08-14T06:00:20.920Z","dependency_job_id":null,"html_url":"https://github.com/Amzd/ResponderChain","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Amzd%2FResponderChain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Amzd%2FResponderChain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Amzd%2FResponderChain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Amzd%2FResponderChain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Amzd","download_url":"https://codeload.github.com/Amzd/ResponderChain/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247266476,"owners_count":20910831,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cross-platform","ios","macos","responder","responder-handling","swift-package-manager","swiftui"],"created_at":"2024-11-05T11:37:25.078Z","updated_at":"2025-04-04T23:31:31.898Z","avatar_url":"https://github.com/Amzd.png","language":"Swift","readme":"As of June 7 2021 this functionality is in the SwiftUI 3 beta. https://developer.apple.com/documentation/SwiftUI/FocusState\n\nThe Apple implementation is a bit different from ResponderChain but switching over looks to be quite easy.\n\nAlso the Apple implementation only supports iOS 15 so I think this repo is still useful for backwards compatibility.\n\n# ⛓️ ResponderChain\n\nCross-platform first responder handling without subclassing views or making custom ViewRepresentables in SwiftUI\n\n## Features\n\n- **💡 Easy to use:** Get, set and resign first responder simply through an EnvironmentObject.\n- **⏰ Time Saving:** If an underlying view can become first responder all you have to do is tag it; and it works!\n- **👀 Insightful:** Gives insight in which views can become first responder.\n\n## Overview\n\nAttach the ResponderChain as environmentObject.\n\n```swift\n// In the SceneDelegate or ApplicationDelegate where you have access to the window:\nlet rootView = Example().environmentObject(ResponderChain(forWindow: window))\n\n// SwiftUI only:\nExample().withResponderChainForCurrentWindow()\n```\n\nTag views that can become first responder.\n\n```swift\nTextField(...).responderTag(\"MyTextField\")\n```\n\nCheck tagged views that are currently available to become first responder.\n\n```swift\nchain.availableResponders.contains(\"MyList\")\n```\n\nMake tagged views become first responder.\n\n```swift\nchain.firstResponder = \"MyTextField\"\nif chain.firstResponder == nil {\n    print(\"Failed\")\n}\n```\n\u003e 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`\n\n\n\nResign first responder.\n\n```swift\nchain.firstResponder = nil\n```\n\u003e **Note:** This only works if the current firstResponder was tagged.\n\n## Example\n\nAttach the ResponderChain as environmentObject.\n\n```swift\n...\n// In the SceneDelegate or ApplicationDelegate where you have access to the window:\nlet rootView = ResponderChainExample().environmentObject(ResponderChain(forWindow: window))\n\n// SwiftUI only:\nResponderChainExample().withResponderChainForCurrentWindow()\n...\n```\n\n**ResponderChainExample.swift**\n```swift\nstruct ResponderChainExample: View {\n    @EnvironmentObject var chain: ResponderChain\n    \n    var body: some View {\n        VStack(spacing: 20) {\n            // Show which view is first responder\n            Text(\"Selected field: \\(chain.firstResponder?.description ?? \"Nothing selected\")\")\n            \n            // Some views that can become first responder\n            TextField(\"0\", text: .constant(\"\"), onCommit: { chain.firstResponder = \"1\" }).responderTag(\"0\")\n            TextField(\"1\", text: .constant(\"\"), onCommit: { chain.firstResponder = \"2\" }).responderTag(\"1\")\n            TextField(\"2\", text: .constant(\"\"), onCommit: { chain.firstResponder = \"3\" }).responderTag(\"2\")\n            TextField(\"3\", text: .constant(\"\"), onCommit: { chain.firstResponder = nil }).responderTag(\"3\")\n            \n            // Buttons to change first responder\n            HStack {\n                Button(\"Select 0\", action: { chain.firstResponder = \"0\" })\n                Button(\"Select 1\", action: { chain.firstResponder = \"1\" })\n                Button(\"Select 2\", action: { chain.firstResponder = \"2\" })\n                Button(\"Select 3\", action: { chain.firstResponder = \"3\" })\n            }\n        }\n        .padding()\n        .onAppear {\n            // Set first responder on appear\n            DispatchQueue.main.async {\n                chain.firstResponder = \"0\"\n            }\n        }\n    }\n}\n```\n\n\u003cimg src=\"ChainResponder.gif\" width=\"300\"\u003e\n","funding_links":["https://github.com/sponsors/Amzd"],"categories":["swiftui"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAmzd%2FResponderChain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAmzd%2FResponderChain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAmzd%2FResponderChain/lists"}