microsoft / microsoft/react-native-windows-samples

Example showing Windows API and weak pointer reference back to ReactModule

Open
#435 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement samples
Dominant language
C#
Stars
544
Forks
218
PR merge metrics
No merged PRs in 30d

Description

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

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?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the existing React Native Windows samples and the entry points for ReactModule callbacks and Windows UI-thread APIs. Use the suggested cursor, pointer-movement, mouse-capture, or fullscreen scenarios to define examples that pass a weak module reference safely; done means the examples demonstrate UI-thread dispatch and callback access without retaining a destroyed module.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, react-native
Domain
documentation, operating-systems
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.