首页 > 解决方案 > 在 iOS 和 Android 中使用本机反应的 webview 组件的性能问题

问题描述

当我运行 React Native 的 WebView 组件时,我遇到了性能问题,只需从该组件加载页面大约需要 11 秒,而从本机代码加载页面需要 2 秒。请有人帮助我,组件的配置可能没有正确分配它。

这是调用组件的代码的一部分:

<Webview
                ref={webviewRef}
                style={{ backgroundColor: colors.WHITE }}
                sharedCookiesEnabled={true}
                startInLoadingState={true}
                bounces={false}
                renderLoading={loadingIndicator}
                showsHorizontalScrollIndicator={false}
                showsVerticalScrollIndicator={false}
                onError={console.error.bind(console, "error")}
                injectedJavaScriptBeforeContentLoaded={didomiJs}
                injectedJavaScript={webviewUtils.injectGetWeviewScrollTop()}
                javaScriptEnabled={true}
                domStorageEnabled={true}
                setSupportMultipleWindows={false}
                originWhitelist={configuration.PROTOCOLS.PROTOCOL_ACCEPTED_IN_WEBVIEWS}
                onMessage={(event) => {
                    onMessage({ event });
                }}
                source={{
                    uri: currentUrl
                }}
                onNavigationStateChange={(navState) => {
                    setCanGoBack(navState.canGoBack);
                }}
                onShouldStartLoadWithRequest={(request) => {
                    return requestOnStart({ request });
                }}
            />

标签: androidiosreact-native

解决方案


推荐阅读