React Native - 使用lockstate跟踪锁定/解锁事件

时间:2018-05-15 17:58:45

标签: react-native locking unlock

我想在React Native中跟踪锁定解锁事件,以便能够衡量在屏幕上花费的时间以及人们解锁手机的次数。我正在尝试使用lockstate(https://www.npmjs.com/package/react-native-lockstate)但我对RN很新,我不太确定它是否也应该连接到AppState或处理它的最佳方式。

我的组件代码如下:

export default class LockStateCheck extends Component {

  state = {
    lockState: RNLockState.currentState
  }

  _handleAppStateChange = (thisLockState) => {
    if (this.state.appState.match(/inactive|background/) && thisLockState === 'active') {
      console.log('App has come to the foreground!')
    };
    this.setState({lockState: thisLockState});
  }

  handleLockStateChange = (thisLockState) => {
    if (this.state.lockState(.match(/lockcomplete/)) && thisLockState === 'unlocked')
  }

  componentDidMount() {
    RNLockState.addEventListener('change', this.handleLockStateChange);
  }

  componentWillUnmount() {
    RNLockState.removeEventListener('change', this.handleLockStateChange);
  }

  render() {
    return (
        <Text></Text>
    );
  }
}

0 个答案:

没有答案