0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ReactNative(Expo)でPinコード画面を利用する

Last updated at Posted at 2019-09-18

以前、見た目が良いという理由でreact-native-pincodeを試してみたが、Expoでは残念ながら動かないことがわかりました。。。

なにげにネットを見ているとreact-native-pin-viewというのがあったので試してみました。

結論

  • react-native-pin-viewは、文字通りviewだけでpinの保持等のロジックは実装されてない
    • ロジックは自分で実装する必要がある

できたもの

スクリーンショット 2019-09-18 9.41.04.png

使い方

インストール

npm install --save react-native-pin-view

実装

pinの入力が完了したらonCompleteが呼ばれるので、そこに色々実装する。
まあ、実際には取得したpinをAsyncStorage等に保存して呼び出す感じになるかと・・・

App.js
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import PinView from 'react-native-pin-view'

export default class App extends React.Component {

    state = {
        pin: '1234'
    }

    onComplete = (inputtedPin,clear) => {
        if(inputtedPin == this.state.pin){
            alert('Pin is correct');
            clear();
        }else{
            clear();
        }
    }

    render() {
        console.log(this.state.pin);
        return (
            <View style={{ flex: 1, justifyContent: 'center', backgroundColor:'#87cefa' }}>
                <PinView
                    pinLength={this.state.pin.length}
                    onComplete={this.onComplete}
                    inputViewStyle={{backgroundColor:"#000"}}
                    inputBgOpacity={0.3}
                />
            </View>
        );
    }
}

まあ、裏でなにやってるのかわからないより、ロジックは自分で実装したほうがスッキリはするかな。。。
デザインはreact-native-pincodeを真似ればいいし。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?