You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public Action AddKeyPressListener(object callback)
{
var cb = ReactUnity.Helpers.Callback.From(callback);
Action<string> listener = null;
listener = (val) => {
if (cb?.callback == null) // Check if we lost reference to cb, if so unsubscribe because we probably lost handle.
{
OnKeyPress -= listener;
return;
}
cb.Call(val);
}
OnKeyPress += listener;
return () => OnKeyPress -= listener;
}
TSX
const [key, setKey] = useState("");
useEffect(() => {
const unsubscribe = Global.Instance.AddKeyPressListener((input: string) => {
setKey(input);
});
// Get current value before hook is called
const input= Global.Instance.LastKeyPressed;
setKey(input);
return () => unsubscribe();
}, []);
The text was updated successfully, but these errors were encountered:
Example code to put in the article
C#
TSX
The text was updated successfully, but these errors were encountered: