Skip to content

Commit a5d01ec

Browse files
authored
Merge pull request #2278 from didi/feat-webview-url
web-view组件改动
2 parents 3b4cade + fdce59e commit a5d01ec

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

packages/webpack-plugin/lib/runtime/components/react/mpx-web-view.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,16 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
127127
style: defaultWebViewStyle
128128
})
129129

130+
const getHostFromUrl = function (url: string): string {
131+
if (!url) return ''
132+
// 匹配协议://主机名(:端口) 的模式
133+
const regex = /^(?:https?|ftp):\/\/([^/?:#]+)(?::(\d+))?/i
134+
const match = url.match(regex)
135+
return match ? match[1] : ''
136+
}
137+
130138
const hostValidate = (url: string) => {
131-
const host = url && new URL(url).host
139+
const host = url && getHostFromUrl(url)
132140
const hostWhitelists = mpx.config.rnConfig?.webviewConfig?.hostWhitelists || []
133141
if (hostWhitelists.length) {
134142
return hostWhitelists.some((item: string) => {
@@ -343,8 +351,9 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
343351
<View style={styles.loadErrorButton} onTouchEnd={_reload}><Text style={{ fontSize: 12, color: '#666666' }}>{currentErrorText.button}</Text></View>
344352
</View>
345353
)
346-
: (<WebView
347-
style={ defaultWebViewStyle }
354+
: (
355+
<WebView
356+
containerStyle={ defaultWebViewStyle }
348357
source={{ uri: src }}
349358
ref={webViewRef}
350359
javaScriptEnabled={true}
@@ -356,7 +365,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
356365
onHttpError={onHttpError}
357366
onError={onError}
358367
allowsBackForwardNavigationGestures={true}
359-
></WebView>)}
368+
></WebView>)}
360369
</Portal>
361370
)
362371
})

0 commit comments

Comments
 (0)