Skip to content
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

[Enhancement] proc + NativeModules #437

Closed
ShaMan123 opened this issue Oct 29, 2019 · 2 comments
Closed

[Enhancement] proc + NativeModules #437

ShaMan123 opened this issue Oct 29, 2019 · 2 comments

Comments

@ShaMan123
Copy link
Contributor

ShaMan123 commented Oct 29, 2019

After playing around with proc I came up with an idea.
I'm after interacting with a native module without going through the bridge (who isn't??).
This is mainly the goal of Animated and especially of reanimated and is the react-native turn off.

So now that proc is live I'm thinking of something as follows:

type NativeMethodProc = (
   moduleName: string, 
   (methodName : string) | (viewManagerCommand: number), 
   ...args: Animated.Value | Animated.Proc
) => Animated.Proc

const methodProc = nativeMethodProc('myCustomModule', 'someNativeMethod', ...(procs | values))

const myVal = new Value(0)
useCode(set(myVal, methodProc(a, b, procSuccess(a1, a2), procFailure(a1))))

The procs passed as args will be in charge of consuming the callback args (onSuccess/onFailure?) that every ReactMethod has. The only thing I'm thinking of are ReadableMaps that are passed back to the callback - I'm guessing there could be an option to reuse event for this purpose.

This approach is valid for dispatchViewManagerCommand as well.
It unlocks endless options (e.g. native state management), complements createAnimatedComponent and sounds to me pretty revolutionary.

A simple use case:

A touch event has started.
I need the absolute layout of a view for some animation calculation.
I need to call UIManager.measure and then set values.
This is a major bottle neck to the UI.

Another use case:

I need to get a value returned for a native module method during a pan gesture event (e.g. if touches are hitting an SVG path)
I'm calling the method from js, so it seems unresponsive.

Ultimate use case:

let's say I'm dragging a view in a ScrollView and want to scroll. With NativeMethodProc I can simply add the proc to my block and scroll freely while panning.

@ShaMan123
Copy link
Contributor Author

#354
@chrfalch mentioning you as you are the author of the PR - wanted to hear your thoughts

@ShaMan123
Copy link
Contributor Author

closing in favor of PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant