[react native] 请问使用 react native scrollable-tab-view 组件时,如何预加载内容?

2016-10-14 18:02:57 +08:00
 maomaomao001

比如 scrollable-tab-view 里有三个 tab 每个的内容是 webview , 怎么才能让他们全都一起开始加载呢?? 现在是只有跳转到某个 tab, 它里面的 webview 才开始加载

代码


import React, { Component } from 'react';
import {
    AppRegistry,
    StyleSheet,
    Text,
    TouchableHighlight,
    View,Navigator,TouchableOpacity,WebView
} from 'react-native';

import ScrollableTabView, {DefaultTabBar, } from 'react-native-scrollable-tab-view';



export class App extends Component {
    constructor(props) {
        super(props);
        this.state = {
            url: 'http://www.bing.com'
        };
    }


    changeTab(tabName,el) {

    }


    renderContent(url) {
        return (

                <WebView
                    style={{ flex: 1 } }
                    ref = "AAA"
                    automaticallyAdjustContentInsets={ false }
                    source={ { uri: url } }
                    javaScriptEnabled={ true }
                    domStorageEnabled={ true }
                    scrollEnabled={ true }
                    decelerationRate="normal"
                    startInLoadingState={ true } />
        );

    }


    render() {
        return (
            <ScrollableTabView

                ref="tabView"

                style={ { marginTop: 20 } }
                onChangeTab={ this.changeTab }
                renderTabBar={ () => <DefaultTabBar /> }
                scrollWithoutAnimation={ true }>
                <View
                    ref ="el1"
                    style={ styles.android }
                    tabLabel='page1'>
                    { this.renderContent('http://v2ex.com') }
                </View>
                <View
                    ref ="el2"
                    style={ styles.android }
                    tabLabel='page2'>
                    { this.renderContent('http://www.baidu.com') }
                </View>
                <View
                    style={ styles.android }
                    ref ="el3"
                    tabLabel='page3'>
                    { this.renderContent('http://global.bing.com/?FORM=HPCNEN&setmkt=en-us&setlang=en-us') }
                </View>
            </ScrollableTabView>


        );
    }

    componentDidMount(){
        this.refs.tabView.goToPage(1);
        this.refs.tabView.goToPage(2);
        this.refs.tabView.goToPage(0);
        // this.refs.tabView.goToPage(0);
        console.log(this);
    }


}

const styles = StyleSheet.create({
    android: {
        flex: 1
    }
});


5872 次点击
所在节点    问与答
1 条回复
maomaomao001
2016-10-14 18:03:33 +08:00
@Kokororin 请帮帮我

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/312847

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX