All Projects → m10c → react-native-touchable-safe

m10c / react-native-touchable-safe

Licence: MIT license
A single easy-to-use `<Touchable>` component, which harnesses the power of all React Native's `Touchable*` components.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-native-touchable-safe

React Native Responsive Dimensions
Resposive fontSize, height and width for react-native components, that automatically adjusts itself based on screen-size of the device.
Stars: ✭ 243 (+1520%)
Mutual labels:  react-native-component
react-native-select-pro
React Native dropdown (select) component developed by Mobile Reality
Stars: ✭ 79 (+426.67%)
Mutual labels:  react-native-component
react-native-window-guard
SafeAreaView alternative for React Native which provides relevant window insets for both iOS and Android.
Stars: ✭ 30 (+100%)
Mutual labels:  react-native-component
react-native-component-splitter
VS Code Extension allows splitting React Native Component into Sub-Component
Stars: ✭ 33 (+120%)
Mutual labels:  react-native-component
expo-ui-kit
expo-ui-kit - a components based React-Native UI Kit
Stars: ✭ 88 (+486.67%)
Mutual labels:  react-native-component
react-native-ios-modal
A react-native component for displaying a modal on iOS by natively wrapping a react-native view inside a UIViewController and presenting it.
Stars: ✭ 94 (+526.67%)
Mutual labels:  react-native-component
React Native Dynamic Search Bar
Medium Article: https://freakycoder.com/react-native-library-dynamic-search-bar-c03fea9fae36
Stars: ✭ 225 (+1400%)
Mutual labels:  react-native-component
react-native-masonry-brick-list
Staggered Or Masonary List View For React Native Written in pure js
Stars: ✭ 24 (+60%)
Mutual labels:  react-native-component
react-native-image-blur-shadow
A React Native Image component with Blur Drop Shadows,100% JavaScript, 0 dependency component. Supports Android, iOS and Web. A light weight <Image/> component for your react native project.
Stars: ✭ 80 (+433.33%)
Mutual labels:  react-native-component
react-native-radio-buttons-group
Simple, best and easy to use radio buttons for react native apps.
Stars: ✭ 145 (+866.67%)
Mutual labels:  react-native-component
react-native-android-notification-listener
React Native Android Notification Listener - Listen for status bar notifications from all applications
Stars: ✭ 87 (+480%)
Mutual labels:  react-native-component
react-native-multi-selectbox
Platform independent (Android / iOS) Selectbox | Picker | Multi-select | Multi-picker. The idea is to bring out the common user interface & user experience on both platforms.
Stars: ✭ 169 (+1026.67%)
Mutual labels:  react-native-component
react-native-carousel-component
React Native Carousel Component for IOS & Android
Stars: ✭ 61 (+306.67%)
Mutual labels:  react-native-component
react-native-touchable
React-Native button helper library
Stars: ✭ 46 (+206.67%)
Mutual labels:  react-native-component
react-native-card-list
A React Native component which displays a list of image cards that zoom to fullscreen
Stars: ✭ 19 (+26.67%)
Mutual labels:  react-native-component
React Native Hero
🤘 A super duper easy hero unit react-native component with support for dynamic image, dynamic sizing, color overlays, and more
Stars: ✭ 234 (+1460%)
Mutual labels:  react-native-component
react-native-chat-ui
Actively maintained, community-driven chat UI implementation with an optional Firebase BaaS.
Stars: ✭ 168 (+1020%)
Mutual labels:  react-native-component
react-native-bubble-tabbar
🧼 Bubble Tab Bar Component for React Native which supports React Navigation V5 and TypeScript
Stars: ✭ 43 (+186.67%)
Mutual labels:  react-native-component
react-native-swipe-action-list
A list view that supports swipe actions for React Native (Android & iOS).
Stars: ✭ 18 (+20%)
Mutual labels:  react-native-component
react-native-uiw
A UI component library based on React Native (Android & iOS).
Stars: ✭ 28 (+86.67%)
Mutual labels:  react-native-component

react-native-touchable-safe

npm version Circle CI Status license npm downloads

A single easy-to-use <Touchable> component, which harnesses the power of all React Native's Touchable* components.

  • Simple API that bridges the differences between RN's various Touchable* types.
  • A consistent View hierarchy, to avoid tricky layout issues when switching between Touchable* types.
  • Handling the incompatability of ripple customisation on Android API level < 21.

Motivation

As it stands, TouchableOpacity and TouchableHighlight wrap their children in a View, whereas TouchableNativeFeedback and TouchableWithoutFeedback do not. This can lead to headaches and platform-specific bugs when trying to create advanced Flexbox layouts with different touchable styles on Android/iOS. An example of this is available here: https://snack.expo.io/ry6kXjX8W

This library makes the situation consistent and easy to reason about:

  • <Touchable> always introduces another view in the hierarchy, which can have its layout customised with outerStyle.
  • <Touchable> always must only have one child, which it applies its effect (e.g. opacity) to natively.

Installation

$ npm install --save react-native-touchable-safe

# Or, with Yarn
$ yarn add react-native-touchable-safe

Getting started

This component provides a simple API, where alternating the component used per platform is as simple as:

return (
  <Touchable android="native" ios="opacity">
    <MyButton />
  </Touchable>
)

In fact, these are the default behaviours, so simply <Touchable> is enough to achieve this effect. The android/ios props only need to be used when deviating from the defaults.

Props

If you don't want to use the defaults (TouchableNativeFeedback on Android and TouchableOpacity on iOS), you can specify another type. Use all to set all platforms to the same effect, or ios and android to differentiate it per platform.

  • all?: 'opacity' | 'highlight' | 'without'
  • ios?: 'opacity' | 'highlight' | 'without' - (default: 'opacity')
  • android?: 'native' | 'opacity' | 'highlight' | 'without' - (default: 'native')

Some very common behaviours used by all touchable types:

  • onPress?: () => void
  • outerStyle?: Object | number - Style to pass to the outer View component which wraps every type of touchable component. Typically used to specify things like <Touchable outerStyle={{ flex: 1 }}>.
  • outerProps?: Object - Similar to outerStyle, but lets you set any props (although style is the main use case).
  • disabled?: boolean - Remove any touch functionality and feedback.

Seeing as setting a custom native ripple requires calling TouchableNativeFeedback.Ripple, the following top-level convenience props can be used to quickly customise the ripple:

  • nativeBorderless?: boolean - For android="native", should the ripple effect be borderless.
  • nativePressColor?: string - (default: 'rgba(0, 0, 0, .1)') - For android="native", what color should the ripple be.

Any props which you only want passed to one type of touchable component can be controlled with the following props.

  • nativeProps?: Object - Any props to pass on to a TouchableNativeFeedback component.
  • opacityProps?: Object - Any props to pass on to a TouchableOpacity component.
  • highlightProps?: Object - Any props to pass on to a TouchableHighlight component.
  • withoutProps?: Object - Any props to pass on to a TouchableWithoutFeedback component.

And finally, anything else will be passed down to all touchable components.

Examples

Defaults

NativeFeedback on Android, Opacity on iOS

import React from 'react'
import Touchable from 'react-native-touchable-safe'
import MyButton from './MyButton'

export default () => (
  <Touchable onPress={() => console.log('Pressed')}>
    <MyButton />
  </Touchable>
)

Mixed

A row of different styled buttons, which all behave consistently

import React from 'react'
import { StyleSheet } from 'react-native'
import Touchable from 'react-native-touchable-safe'
import MyButton from './MyButton'

export default ({ disabled }) => (
  <View style={styles.row}>
    {/* Android: native, iOS: highlight */}
    <Touchable
      ios="highlight"
      onPress={() => {
        console.log('Pressed A')
      }}
      outerStyle={styles.touchWrap}
      nativeBorderless
      nativePressColor="rgba(0, 0, 255, .5)"
    >
      <MyButton title="A" />
    </Touchable>

    {/* Both: opacity (50% opacity) */}
    <Touchable
      all="opacity"
      onPress={() => {
        console.log('Pressed B')
      }}
      outerStyle={styles.touchWrap}
      opacityProps={{ activeOpacity: 0.5 }}
    >
      <MyButton title="B" />
    </Touchable>

    {/* Both: no feedback */}
    <Touchable
      all="without"
      onPress={() => {
        console.log('Pressed C')
      }}
      outerStyle={styles.touchWrap}
    >
      <MyButton title="C" />
    </Touchable>

    {/* Both: defaults, disabled based on prop */}
    <Touchable
      onPress={() => {
        console.log('Pressed D')
      }}
      outerStyle={styles.touchWrap}
      disabled={disabled}
    >
      {/* Visual styling of disabled elements handled manually */}
      <MyButton title="D" greyedOut={disabled} />
    </Touchable>
  </View>
)

const styles = StyleSheet.create({
  row: {
    flexDirection: 'row',
    alignItems: 'top',
    height: 200,
  },
  touchWrap: {
    flex: 1,
    height: 100,
  },
})
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].