设置PinCode锁住屏幕时是很常见的场景,下面教程是使用react-native-pincode开源组件来实现react-native锁住手机屏幕的功能。
该组件官方地址:
https://github.com/jarden-digital/react-native-pincode
yarn add @haskkor/react-native-pincode @react-native-community/async-storage react-native-keychain@5.0.1
2. 因为组件使用了系统提供的VIBRATE,所以在android/app/src/main/AndroidManifest.xml文件夹添加权限:
3.使用:
import React, {useCallback, useEffect, useState} from 'react';
import {View, StyleSheet} from 'react-native';
import {RouterStackScreenProps} from '../../types/types';
import PINCode, {hasUserSetPinCode} from '@haskkor/react-native-pincode';
import {setShowPinLock} from '../../redux/reducers/userReducer';
import {useAppDispatch} from '../../hooks/redux-hooks';
type LoginScreenProps = RouterStackScreenProps<'LoginScreen'>;
const LoginScreen = ({route, navigation}: LoginScreenProps) => {
const dispatch = useAppDispatch();
const [pinCodeStatus, setPinCodeStatus] = useState(false);
const hasPin = useCallback(async () => {
const data = await hasUserSetPinCode();
setPinCodeStatus(data);
}, []);
useEffect(() => {
hasPin().catch(console.error);
}, [hasPin]);
console.log('hasPin:', hasPin());
return (
{
dispatch(setShowPinLock(false));
navigation.navigate('TabNavigator', {
screen: 'HomeScreen',
});
}}
/>
);
};
export default LoginScreen;
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
},
});
代码说明:
留言与评论(共有 0 条评论) “” |