-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from hotwired/strada-sample
Strada sample components in the Demo app
- Loading branch information
Showing
13 changed files
with
466 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
Demo/Demo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
{ | ||
"pins" : [ | ||
{ | ||
"identity" : "cwlcatchexception", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/mattgallagher/CwlCatchException.git", | ||
"state" : { | ||
"revision" : "3b123999de19bf04905bc1dfdb76f817b0f2cc00", | ||
"version" : "2.1.2" | ||
} | ||
}, | ||
{ | ||
"identity" : "cwlpreconditiontesting", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/mattgallagher/CwlPreconditionTesting.git", | ||
"state" : { | ||
"revision" : "a23ded2c91df9156628a6996ab4f347526f17b6b", | ||
"version" : "2.1.2" | ||
} | ||
}, | ||
{ | ||
"identity" : "nimble", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/quick/nimble", | ||
"state" : { | ||
"revision" : "1f3bde57bde12f5e7b07909848c071e9b73d6edc", | ||
"version" : "10.0.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "ohhttpstubs", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/AliSoftware/OHHTTPStubs", | ||
"state" : { | ||
"revision" : "12f19662426d0434d6c330c6974d53e2eb10ecd9", | ||
"version" : "9.1.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "quick", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/quick/quick", | ||
"state" : { | ||
"revision" : "f9d519828bb03dfc8125467d8f7b93131951124c", | ||
"version" : "5.0.1" | ||
} | ||
}, | ||
{ | ||
"identity" : "strada-ios", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/hotwired/strada-ios.git", | ||
"state" : { | ||
"branch" : "main", | ||
"revision" : "3f8e6a0a07d2361bb3a64a6e6a945124eed20ccf" | ||
} | ||
}, | ||
{ | ||
"identity" : "swifter", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/httpswift/swifter.git", | ||
"state" : { | ||
"revision" : "9483a5d459b45c3ffd059f7b55f9638e268632fd", | ||
"version" : "1.5.0" | ||
} | ||
} | ||
], | ||
"version" : 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Foundation | ||
import Strada | ||
|
||
extension BridgeComponent { | ||
static var allTypes: [BridgeComponent.Type] { | ||
[ | ||
FormComponent.self, | ||
MenuComponent.self, | ||
OverflowMenuComponent.self | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import Foundation | ||
import Strada | ||
import UIKit | ||
|
||
/// Bridge component to display a submit button in the native toolbar, | ||
/// which will submit the form on the page when tapped. | ||
final class FormComponent: BridgeComponent { | ||
override class var name: String { "form" } | ||
|
||
override func onReceive(message: Message) { | ||
guard let event = Event(rawValue: message.event) else { | ||
return | ||
} | ||
|
||
switch event { | ||
case .connect: | ||
handleConnectEvent(message: message) | ||
case .submitEnabled: | ||
handleSubmitEnabled() | ||
case .submitDisabled: | ||
handleSubmitDisabled() | ||
} | ||
} | ||
|
||
@objc func performAction() { | ||
reply(to: Event.connect.rawValue) | ||
} | ||
|
||
// MARK: Private | ||
|
||
private weak var submitBarButtonItem: UIBarButtonItem? | ||
private var viewController: UIViewController? { | ||
delegate.destination as? UIViewController | ||
} | ||
|
||
private func handleConnectEvent(message: Message) { | ||
guard let data: MessageData = message.data() else { return } | ||
configureBarButton(with: data.submitTitle) | ||
} | ||
|
||
private func handleSubmitEnabled() { | ||
submitBarButtonItem?.isEnabled = true | ||
} | ||
|
||
private func handleSubmitDisabled() { | ||
submitBarButtonItem?.isEnabled = false | ||
} | ||
|
||
private func configureBarButton(with title: String) { | ||
guard let viewController else { return } | ||
|
||
let item = UIBarButtonItem(title: title, | ||
style: .plain, | ||
target: self, | ||
action: #selector(performAction)) | ||
|
||
viewController.navigationItem.rightBarButtonItem = item | ||
submitBarButtonItem = item | ||
} | ||
} | ||
|
||
// MARK: Events | ||
|
||
private extension FormComponent { | ||
enum Event: String { | ||
case connect | ||
case submitEnabled | ||
case submitDisabled | ||
} | ||
} | ||
|
||
// MARK: Message data | ||
|
||
private extension FormComponent { | ||
struct MessageData: Decodable { | ||
let submitTitle: String | ||
} | ||
} | ||
|
Oops, something went wrong.