-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(taro-components-rn): 增加 WebView, close #2336
- Loading branch information
Showing
4 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React, { Component } from 'react' | ||
import { WebView } from '../src' | ||
|
||
export default class EXSlider extends Component { | ||
render () { | ||
return ( | ||
<WebView src="https://taro.aotu.io/" style={{ width: 300, height: 150 }} /> | ||
) | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
packages/taro-components-rn/src/components/WebView/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* ✔ src | ||
* ✔ onMessage(bindmessage) | ||
* ✔ onLoad(bindload) | ||
* ✔ onError(binderror) | ||
* | ||
* 注意:onMessage 每次调用都会执行(小程序在特定时机触发),RN WebView 调用 window.postMessage 只接收一个字符串参数 | ||
* | ||
* @flow | ||
*/ | ||
|
||
import * as React from 'react' | ||
import { | ||
WebView, | ||
StyleSheet, | ||
} from 'react-native' | ||
const utils = require('../../utils') | ||
|
||
type Props = { | ||
style?: StyleSheet.Styles, | ||
src?: boolean, | ||
onMessage?: Function, | ||
onLoad?: Function, | ||
onError?: Function, | ||
} | ||
|
||
export default function _WebView ({ | ||
style, | ||
src, | ||
onMessage = utils.noop, | ||
onLoad = utils.noop, | ||
onError = utils.noop, | ||
}: Props) { | ||
return ( | ||
<WebView | ||
source={{ uri: src }} | ||
onMessage={(event) => { | ||
onMessage({ | ||
detail: { | ||
data: [event.nativeEvent.data] | ||
} | ||
}) | ||
}} | ||
onLoad={() => { | ||
onLoad({ | ||
detail: { src } | ||
}) | ||
}} | ||
onError={() => { | ||
onError({ | ||
detail: { src } | ||
}) | ||
}} | ||
style={style} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters