首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于侦听器的防火墙和本机反应

基于侦听器的防火墙和本机反应
EN

Stack Overflow用户
提问于 2019-02-15 11:20:53
回答 1查看 2.7K关注 0票数 3

因此,我试图附加一个.on侦听器,如下所示

代码语言:javascript
复制
firebase.database().ref('Users').child('AhvRcIT2anTaucSDoOgt2MLNxgZ2').on('value', snap => {
    const user = snap.val();
    alert(true);
}).catch(e => alert(e))

问题是,我说错了

设置一个长时间的定时器,即多分钟,在Android上是一个性能和正确性问题,因为它使计时器模块保持清醒,只有在应用程序处于前台时才能调用计时器。有关更多信息,请参见https://github.com/facebook/react-native/issues/12981。(Saw setTimeout的持续时间为398331 Saw)

我想这是有道理的。我唯一能找到的解决办法就是把警告藏起来,这听起来是个坏主意。特别是当我添加这个侦听器时,我的应用程序在一段时间后就开始冻结。

我知道react-native-firebase是可用的,但我已经读过它所做的一切,只是隐藏警告,而不是真正解决问题。

但如何解决这个问题呢?还是只需要在Android上像这样呢?

整个家庭课

代码语言:javascript
复制
export default class HomeScreen extends React.Component {
    static navigationOptions = {
        header: null,
    };

    componentWillMount() {
        (async () => {
            await firebase.auth().signInAndRetrieveDataWithEmailAndPassword('loigin', 'pass');
            const val = await firebase.database().ref('Users').child('AhvRcIT2anTaucSDoOgt2MLNxgZ2').once('value').then(r => r.val()).catch(e => alert(e));
            alert(val);
        })();
    }


    render() {
        // firebase.database().ref('Users').child('AhvRcIT2anTaucSDoOgt2MLNxgZ2').on('value', snap => {
        //     const user = snap.val();
        //     alert(true);
        // }).catch(e => alert(e))
        alert(false)
        return (
            <View style={styles.container}>
                <ScrollView style={styles.container} contentContainerStyle={styles.contentContainer}>
                    <View style={styles.welcomeContainer}>
                        <Image
                            source={
                                __DEV__
                                    ? require('../assets/images/robot-dev.png')
                                    : require('../assets/images/robot-prod.png')
                            }
                            style={styles.welcomeImage}
                        />
                    </View>

                    <View style={styles.getStartedContainer}>
                        {this._maybeRenderDevelopmentModeWarning()}

                        <Text style={styles.getStartedText}>Get started by opening</Text>

                        <View style={[styles.codeHighlightContainer, styles.homeScreenFilename]}>
                            <MonoText style={styles.codeHighlightText}>screens/HomeScreen.js</MonoText>
                        </View>

                        <Text style={styles.getStartedText}>
                            Change this text and your app will automatically reload.
                        </Text>
                    </View>

                    <View style={styles.helpContainer}>
                        <TouchableOpacity onPress={this._handleHelpPress} style={styles.helpLink}>
                            <Text style={styles.helpLinkText}>Help, it didn’t automatically reload!</Text>
                        </TouchableOpacity>
                    </View>
                </ScrollView>

                <View style={styles.tabBarInfoContainer}>
                    <Text style={styles.tabBarInfoText}>This is a tab bar. You can edit it in:</Text>

                    <View style={[styles.codeHighlightContainer, styles.navigationFilename]}>
                        <MonoText style={styles.codeHighlightText}>navigation/MainTabNavigator.js</MonoText>
                    </View>
                </View>
            </View>
        );
    }

    _maybeRenderDevelopmentModeWarning() {
        if (__DEV__) {
            const learnMoreButton = (
                <Text onPress={this._handleLearnMorePress} style={styles.helpLinkText}>
                    Learn more
                </Text>
            );

            return (
                <Text style={styles.developmentModeText}>
                    Development mode is enabled, your app will be slower but you can use useful development
                    tools. {learnMoreButton}
                </Text>
            );
        } else {
            return (
                <Text style={styles.developmentModeText}>
                    You are not in development mode, your app will run at full speed.
                </Text>
            );
        }
    }

    _handleLearnMorePress = () => {
        WebBrowser.openBrowserAsync('https://docs.expo.io/versions/latest/guides/development-mode');
    };

    _handleHelpPress = () => {
        WebBrowser.openBrowserAsync(
            'https://docs.expo.io/versions/latest/guides/up-and-running.html#can-t-see-your-changes'
        );
    };
}
EN

回答 1

Stack Overflow用户

发布于 2019-02-15 11:51:19

您可以在下面尝试获取componentWillMount

代码语言:javascript
复制
 componentWillMount() {
            firebase
            .auth()
            .createUserWithEmailAndPassword('loigin', 'pass')
            .then(() => {

                firebase.database()
                    .ref('Users')
                    .child('AhvRcIT2anTaucSDoOgt2MLNxgZ2').on('value', function (snapshot) {
                        alert(snapshot.val())
                    })
                    .catch(e => alert(e));

            })
            .catch(error => {
                alert(error.message)
            })
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54708232

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档