Example #1
0
const Sms = {
    getSupportedCountries(cb){
        cb && this._addEventListener(SmsNative.DidGetSupportedCountries, cb);
        SmsNative.getSupportedCountries();
    },

    getVerificationCode(country, phone, cb){
        cb && this._addEventListener(SmsNative.DidGetVerificationCode, cb);
        SmsNative.getVerificationCode(country, phone);
    },

    submitVerificationCode(country, phone, code, cb){
        cb && this._addEventListener(SmsNative.DidSubmitVerificationCode, cb);
        SmsNative.submitVerificationCode(country, phone, code);
    },

    _addEventListener(eventName, handler){
        if (Platform.OS === 'android'){
            return DeviceEventEmitter.once(eventName, (event)=>{
                handler(event);
            });
        } else if (Platform.OS === 'ios'){
            subscription && subscription.remove();
            subscription = NativeAppEventEmitter.addListener(eventName, (event)=>{
                handler(event);
            });
        }
    }
}

export default Sms;