react-native-windows-samples
react-native-windows-samples copied to clipboard
Example showing Windows API and weak pointer reference back to ReactModule
In some cases windows APIs need to be on the UI thread (different than thread react native is running on).
Sometimes people might pass a get_weak() or get_this() into the lambda of some windows api. However there are several nuances around this that can complicate things.
c++ std has std::enabled_shared_from_this() and winrt c++ has some public implement<thisClass>
Both either get_this() or get_shared_from_this() to pass into the lambda. Which isn't right either. They should be passing in weak references of the module into the callback, in case the RN module is destroyed right before callback happens.
It'd be great to have some kind of example scenarios of calling into any windows api that requires ui threading and needs access to a variable from the react module.
I know this is a deeply complex topic (multithreading, with mutex/locks, and other things). But even a couple of basic examples would be great example/reference, when intermingly with ReactModules.
Some suggested windows api calls.
- Windows API has something to show/hide cursor.
- Windows API has api for UI Thread OnPointerMoved (grab the x/y coordinates or something).
- example of passing back to RN module to query for REACT_METHOD GetMousePosition() or something.
- toggle mouse capture (needs ui thread)
- toggle fullscreen, I think needs dispached to main application thread? ui thread?