Focus Management: Get currently focused element
Introduction
Hi :wave:! On Web (ReactJS/RNW) the blur event contains info about the new to-be-focused element (nativeEvent.relatedTarget). This is really helpful to know how to act in certain scenarios. Unfortunately, we don't have such a feature on Native. But can we have it? Or get close to it?
Details
I understand that we may not have control over the blur event due to host limitations. However, the value we are looking for here is not strictly tied to the blur event i.e. nativeEvent.relatedTarget will return the newly focused element. So as an alternative can we just ask the OS which element is currently focused?
I'm looking to understand the requirements/challenges that may be blocking us from implementing this feature.
Discussion points
- How can we ask the OS to return the currently focused element?
- How can we map the returned value to a react component?
- If we can't map it (easily), can we instead get the native id (the one that we pass as
nativeID) of that element?
How can we ask the OS to return the currently focused element?
- On Android we have
getCurrentFocusmethods such as https://developer.android.com/reference/android/view/Window#getCurrentFocus() - On iOS I'm not sure but maybe we can achieve that using
firstResponderhttps://developer.apple.com/documentation/appkit/nswindow/1419440-firstresponder?language=objc