NoriginMedia / react-spatial-navigation

DEPRECATED. HOC-based Spatial Navigation. NEW Hooks version is available here: https://github.com/NoriginMedia/norigin-spatial-navigation
MIT License
226 stars 64 forks source link

Fire `onClick` when enter pressed of `button` like `onPress` example with `TouchableOpacity` #38

Closed stuartflanagan closed 5 years ago

stuartflanagan commented 5 years ago

To Reproduce When looking at the basic example provided, onPress is triggered when using a ReactNative TouchableOpacity component as well as onEnterPress. This does not occur with a regular HTML button element with onClick. Is this possible to achieve the same behaviour with a button and trigger the click as well? Just wondering how the React Native onPress is being fired.

Example:

import {withFocusable} from '@noriginmedia/react-spatial-navigation';

const ComponentTouchableOpacity = ({focused}) => (
  <TouchableOpacity 
    // This gets triggered 
    onPress={() => {
        console.log('TouchableOpacity::onPress');
    }}
  />
);

const FocusableComponent = withFocusable()(ComponentTouchableOpacity);

const ComponentButton = ({focused}) => (
  <button 
    // This gets triggered 
    onClick={() => {
        console.log('TouchableOpacity::onPress');
    }}
  />);

const FocusableComponent = withFocusable()(ComponentButton);
asgvard commented 5 years ago

TouchableOpacity might implement its own listener to enter key and trigger onPress. This library is not responsible for this kind of callbacks from the elements itself since it is agnostic of which elements you wrap into withFocusable. onEnterPress will be triggered, this should be sufficient to implement the logic of listening to enter key press.

stuartflanagan commented 5 years ago

Thank you it is interesting that it knows it has focus though. As it has not been given focus natively.