设置一个长时间的计时器,即几分钟 [英] Setting a timer for a long period of time, i.e. multiple minutes

查看:47
本文介绍了设置一个长时间的计时器,即几分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对 LoginSignup 使用带有 react native 的 firebase 身份验证,但出现黄色错误:

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

将计时器设置为长时间(即几分钟)是 Android 上的性能和正确性问题,因为它会使计时器模块保持唤醒状态,并且计时器只能在应用程序处于前台时调用.请参阅 (https://github.com/facebook/react-native/issues/12981) 了解更多信息.(看到持续时间为 111862ms 的 setTimeout)

Setting a timer for a long period of time, i.e. multiple minutes, is a performance and correctness issue on Android as it keeps the timer module awake, and timers can only be called when the app is in the foreground. See (https://github.com/facebook/react-native/issues/12981) for more info. (Saw setTimeout with duration 111862ms)

我该如何解决?
我不想忽略这一点,我想了解这个错误并以最佳和标准的方式解决它.
这是我的代码:

How Can I Fix That?
I don't want to ignore that, I want to understand this error and solve that with the best and Standard way.
And This is my Code:

  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 团队报告:(https://github.com/firebase/firebase-js-sdk/issues/97)

推荐答案

Google 的软件工程师 Josh Crowther 说:

Josh Crowther Software Engineer at Google Said:

虽然使用多步短持续时间 setTimeouts 实际上并不能解决问题.Timer 模块仍然保持活动状态,应用程序仍然受到警告中指出的性能问题的影响.这里的问题是,我们有需要长时间计时器的用例,而 react-native 并未针对该用例进行优化.

Using multi-step short duration setTimeouts doesn't actually fix the problem though. The Timer module still stays active and the app is still subject to the performance issues indicated in the warning. The issue here is that, we have use cases that require long timers, and react-native doesn't optimize for that use case.

所以所有的网是:这个错误不能在这里修复我们只能解决错误有可用的解决方法(请参阅设置一个长时间的计时器,即多分钟) 禁用警告.在我们的代码中禁用警告的工作无助于解决问题(除了禁用警告),并且添加了完全不必要的额外 SDK 代码/权重.

So the net of all that is: This bug can't be fixed here we can only work around the error there are workarounds available (see Setting a timer for a long period of time, i.e. multiple minutes) that disable the warning. Doing the work to disable the warning in our code, doesn't help the issue (beyond disabling the warning), and adds additional SDK code/weight that is completely unnecessary.

我建议就上述问题发表意见(即 facebook/react-native#12981) 如果您对所提供的解决方法不满意

I'd recommend chiming in on the issue mentioned above (i.e. facebook/react-native#12981) if you aren't comfortable w/ the workaround provided

这篇关于设置一个长时间的计时器,即几分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆