-
Notifications
You must be signed in to change notification settings - Fork 58
Add beforeTransition hook to Flow and parity test [iOS] #803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a73b798
e470118
d609056
44d01bd
d21f563
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,6 +108,31 @@ public class Hook2<T, U>: BaseJSHook where T: CreatedFromJSValue, U: CreatedFrom | |
| } | ||
| } | ||
|
|
||
| /** | ||
| A waterfall hook with 2 parameters. The handler receives (state, transitionValue) and must return | ||
| the state so the JS runtime can pass it to the next tap or use it as the result. | ||
| Used for flow hooks like beforeTransition where the return value is the (possibly modified) state. | ||
| Aligns with FlowHooks.transition and afterTransition: use tap { state, transitionValue in ... return state }. | ||
| */ | ||
| public class WaterfallHook2: BaseJSHook { | ||
| /** | ||
| Attach a closure to the hook. When the hook is fired in the JS runtime, the handler receives | ||
| the current state as NavigationBaseState? and the transition value as String. Return the state | ||
| (pass-through or modified), or nil to pass through the original state. | ||
| - parameters: | ||
| - hook: A function (state, transitionValue) -> state (or nil to pass through) | ||
| */ | ||
| public func tap(_ hook: @escaping (NavigationBaseState?, String) -> NavigationBaseState?) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we make this generic so it’s reusable and aligned with web’s SyncWaterfallHook? |
||
| let tapMethod: @convention(block) (JSValue?, JSValue?) -> JSValue? = { value, value2 in | ||
| guard let val = value, let val2 = value2 else { return nil } | ||
| let transitionValue = val2.toString() ?? "" | ||
| let typedState = NavigationBaseState.createInstance(value: val) | ||
| return hook(typedState, transitionValue)?.jsValue ?? val | ||
| } | ||
|
Comment on lines
+126
to
+131
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Can we do let tapMethod: @convention(block) (JSValue?, JSValue?) -> JSValue? = { value1, value2 in
guard let value1, let value2 else { return nil }
let transitionValue = value2.toString() ?? ""
let typedState = NavigationBaseState.createInstance(value: value1)
return hook(typedState, transitionValue)?.jsValue ?? value1
} |
||
| self.hook.invokeMethod("tap", withArguments: [name, JSValue(object: tapMethod, in: context) as Any]) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| This class represents an object in the JS runtime that can be tapped into | ||
| to receive JS events | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be public?