1.0.41 • Published 4 years ago

react-native-platform-specific-hook-selector v1.0.41

Weekly downloads
4
License
ISC
Repository
github
Last release
4 years ago

react-native-platform-specific-hook-selector

Hook based simple wrapper for actionSheetIOS and native android picker. under the hood on IOS it uses actionSheetIOS and on android react-native-dialogs(because native android Picker don't have any method for calling it programmatically)

Showcase IOSShowcase Android
npm.ionpm.io

Installation

npm i react-native-platform-specific-hook-selector react-native-dialogs --save

or

yarn add react-native-platform-specific-hook-selector react-native-dialogs

Example

import React, {useEffect} from 'react';
import {SafeAreaView, Text, StatusBar, Button, Alert} from 'react-native';

import useBaseActionSheetPicker from 'react-native-platform-specific-hook-selector';

const App = () => {
  const {selectedItem, renderPicker} = useBaseActionSheetPicker({
    cancelText: 'Cancel',
    title: 'Choose color',
  });

  useEffect(() => {
    if (selectedItem) {
      Alert.alert(selectedItem);
    }
  }, [selectedItem]);

  return (
    <>
      <StatusBar barStyle="dark-content" />
      <SafeAreaView>
        <Button
          onPress={() => renderPicker(['green', 'blue', 'red'])}
          title={'Choose color'}
        />
        <Text>{selectedItem}</Text>
      </SafeAreaView>
    </>
  );
};

export default App;

Predefined hook arguments

paramtypedescription
cancelTextStringCancel text on IOS
titleStringtitle on both platform
onCancelcallbackreturn on close event

hook returned values

valuestypedescription
selectedItemString or undefinedvalue that has been selected
renderPicker( params: string[] ) => voidrenderer

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Credits

react-native-dialogs

Author

Made with ❤️ by beqramo.