0.3.2 • Published 1 year ago

react-native-sms-code v0.3.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

react-native-sms-code

The purpose of this package is provide SMS verification codes on Android devices.

Installation

npm install react-native-sms-code
yarn add react-native-sms-code

Usage

import {
registerBroadcastReceiver,
codeReceived,
unregisterBroadcastReceiver,
} from 'react-native-sms-code';


// ...
const [code, setCode] = React.useState('');

const handleCodeReceived = async () => {
  try {
    const otpCode = await codeReceived();
    setCode(otpCode);
  } catch (e) {
    console.log('error', e);
  }
};

React.useEffect(() => {
  registerBroadcastReceiver();

  handleCodeReceived();

  return () => {
    unregisterBroadcastReceiver();
  };

}, []);


return (
  <View style={styles.container}>
    <Text>Code:</Text>
    <TextInput
      value={code}
      onChangeText={setCode}
      underlineColorAndroid="#3333"
    />
  </View>
);

const styles = StyleSheet.create({
  container: {
  flex: 1,
  justifyContent: 'center',
  padding: 8,
  },
  box: {
  width: 60,
  height: 60,
  marginVertical: 20,
  },
  textInput: {
  width: '100%',
  },
});

Demonstration

Extra Parameter

codeLength()

The length of the code to be received. Default is 6.

## License

MIT