0.1.1 • Published 3 years ago

rn-interactive v0.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

rn-interactive

npm npm bundle size (version) npm type definitions

Handle interactions with your components effectively across platforms

  • Consistent API across desktop and touch devices
  • DOM events handled by React
  • Only 932 bytes gzipped

Installation

npm install rn-interactive

Usage example

import { Interactive } from 'rn-interactive';

function Button({ disabled = false }) {
  return (
    <Interactive disabled={disabled}>
      {({ isHovered, isFocused, isPressed }) => (
        <View
          accessibilityRole="button"
          accessible={!disabled}
          style={[
            styles.button,
            isHovered && styles.hovered,
            isFocused && styles.focused,
            isPressed && styles.pressed,
            disabled && styles.disabled,
          ]}
        >
          <Text>{title}</Text>
        </View>
      )}
    </Interactive>
  );
}

API

Interactive

Create an Interactive component

PropsTypeDescription
childrenElement or FunctionElement or callback providing the current state.
disabledbooleanPrevents the interaction when enabled. Default to false.
onHoverInfunctionCallback when the element is hovered.
onHoverOutfunctionCallback when the element loses the hovered state.
onPressInfunctionCallback when the element is pressed.
onPressOutfunctionCallback when the element loses the pressed state.
onFocusInfunctionCallback when the element is focused.
onFocusOutfunctionCallback when the element loses the focused state.