I want to use firebase auth with react native for 100 and 101 but I got a yellow error:

在安卓系统上,设置一个长时间(即多分钟)的计时器是一个性能和正确性问题,因为它会让计时器模块保持唤醒状态,并且计时器只能在应用程序位于前台时调用.更多信息请参见(https://github.com/facebook/react-native/issues/12981).(Saw设置超时,持续时间为111862ms)

How Can I Fix That?

  export default class Login extends Component {
        constructor(props) {
            super(props)
            this.state = {
                email: '',
                password: '',
                response: ''
            }
            this.signUp = this.signUp.bind(this)
            this.login = this.login.bind(this)
        }
        async signUp() {
            try {
                await firebase.auth().createUserWithEmailAndPassword(this.state.email, this.state.password)
                this.setState({
                    response: 'Account Created!'
                })
                setTimeout(() => {
                    this.props.navigator.push({
                        id: 'App'
                    })
                }, 1500)
            } catch (error) {
                this.setState({
                    response: error.toString()
                })
            }
        }
        async login() {
            try {
                await firebase.auth().createUserWithEmailAndPassword(this.state.email, this.state.password)
                this.setState({
                    response: 'user login in'
                })
                setTimeout(() => {
                    this.props.navigator.push({
                        id: 'App'
                    })
                })

            } catch (error) {
                this.setState({
                    response: error.toString()
                })
            }

        }
        render() {
            return (
                <View style={styles.container}>
                    <View style={styles.containerInputes}>
                        <TextInput
                            placeholderTextColor="gray"
                            placeholder="Email"
                            style={styles.inputText}
                          //  onChangeText={(email) => this.setState({ email })}
                            onChangeText={(email) => {console.log(email);}}
                        />
                        <TextInput
                            placeholderTextColor="gray"
                            placeholder="Password"
                            style={styles.inputText}
                            password={true}
                            onChangeText={(password) => this.setState({ password })}
                        />
                    </View>
                    <TouchableHighlight
                        onPress={this.login}
                        style={[styles.loginButton, styles.button]}
                    >
                        <Text
                            style={styles.textButton}
                        >Login</Text>
                    </TouchableHighlight>
                    <TouchableHighlight
                        onPress={this.signUp}
                        style={[styles.loginButton, styles.button]}
                    >
                        <Text
                            style={styles.textButton}
                        >Signup</Text>
                    </TouchableHighlight>
                </View>
            )
        }
    }

我向Google Firebase Team报告:(https://github.com/firebase/firebase-js-sdk/issues/97)

推荐答案

谷歌的软件工程师Josh Crowther说:

不过,使用多步短时设置超时实际上并不能解决这个问题.计时器模块仍处于活动状态,应用程序仍存在警告中指出的性能问题.这里的问题是,我们有需要很长时间的用例,react native没有针对该用例进行优化.

因此,所有这些都是:这个错误在这里无法修复,我们只能解决这个错误.有一些解决方法(见Setting a timer for a long period of time, i.e. multiple minutes)可以禁用警告.在我们的代码中禁用警告并没有帮助解决问题(除了禁用警告之外),并且添加了完全不必要的额外SDK代码/权重.

如果你对提供的解决方案不满意,我建议你就上述问题(即facebook/react-native#12981)进行咨询

React-native相关问答推荐

使用FETCH发送BLOB/文件时为空

React native React native下拉 Select 器下拉列表不透明问题

TypeError:未定义不是对象(判断'theme.spacing [radius]')

检索元素的父项时出错:找不到与给定名称android:TextAppearance.Material.Widget.Button.Colored匹配的资源

React-native 在浏览器中打开链接并返回应用程序

使用带有 react-native 的 WebView 设置用户代理

如何在 React Navigation createStackNavigator 中更改字体系列

React Native 错误找不到模块metro-config/src/defaults/blacklist

如何使用 InteractionManager.runAfterInteractions 使导航器过渡更快

在使用 redux-persist 重新水化存储之前加载初始状态的默认值

React Native:fetch request failed with error - TypeError: Network request failed(…)

为什么 Android Studio 强制使用 Android 支持库中的 Androidx?

React Navigation TabNavigator:在选项卡更改时重置上一个选项卡

React Native:ScrollView 中的 TouchableOpacity onPress 问题

React Native:当我从 XCode 运行应用程序时看不到 console.logs

无法判断模块react-native-maps:找不到名称为 default的配置

使用 expo SDK react-native ios 应用程序的 Info.plist 文件

如何知道 FlatList 中的滚动状态?

React Native:使用选项卡动画收缩标题

React 本机矢量图标在当前版本 0.60 上不起作用