-
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(components): 新增 WebView 组件 close #2018
- Loading branch information
1 parent
c2c28ea
commit fd57e13
Showing
4 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
packages/taro-components/src/components/web-view/__test__/web-view.test.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,18 @@ | ||
import Nerv from 'nervjs' | ||
import { renderIntoDocument } from 'nerv-test-utils' | ||
import WebView from '../index' | ||
|
||
describe('WebView', () => { | ||
it('render WebView', () => { | ||
const onLoadSpy = jest.fn() | ||
const view = <WebView src='https://www.baidu.com' /> | ||
const component = renderIntoDocument(view) | ||
|
||
const loadEvent = document.createEvent('Event') | ||
loadEvent.initEvent('load', false, false) | ||
// const dom = Nerv.findDOMNode(component) | ||
// expect(dom.textContent).toEqual('hello taro') | ||
component.getDOMNode().dispatchEvent(loadEvent) | ||
expect(onLoadSpy).toHaveBeenCalled() | ||
}) | ||
}) |
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,33 @@ | ||
import Nerv from 'nervjs' | ||
import omit from 'omit.js' | ||
import './style/index.scss' | ||
|
||
class WebView extends Nerv.Component { | ||
constructor () { | ||
super(...arguments) | ||
this.onLoad = this.onLoad.bind(this) | ||
this.onError = this.onError.bind(this) | ||
} | ||
|
||
onLoad (e) { | ||
const { onLoad } = this.props | ||
onLoad && onLoad(e) | ||
} | ||
|
||
onError (e) { | ||
const { onError } = this.props | ||
onError && onError(e) | ||
} | ||
|
||
render () { | ||
const { | ||
src, | ||
...other | ||
} = this.props | ||
return ( | ||
<iframe className='taro-webview' onLoad={this.onLoad} onError={this.onError} {...omit(this.props, ['src', 'className'])} src={src} {...other} /> | ||
) | ||
} | ||
} | ||
|
||
export default WebView |
11 changes: 11 additions & 0 deletions
11
packages/taro-components/src/components/web-view/style/index.scss
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,11 @@ | ||
iframe { | ||
border: none; | ||
} | ||
.taro-webview { | ||
position: fixed; | ||
top: 0; | ||
bottom: 0; | ||
width: 100%; | ||
height: 100%; | ||
z-index: 999; | ||
} |
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