Skip to content
Permalink
Browse files

feat(components): 新增 WebView 组件 close #2018

  • Loading branch information...
jinjinjin0731 committed Jan 24, 2019
1 parent c2c28ea commit fd57e13e8f5adf99301892eb3cb9b1b7632c2827
@@ -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()
})
})
@@ -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
@@ -0,0 +1,11 @@
iframe {
border: none;
}
.taro-webview {
position: fixed;
top: 0;
bottom: 0;
width: 100%;
height: 100%;
z-index: 999;
}
@@ -26,3 +26,4 @@ export { default as Tabbar } from './components/tabbar'
export { default as TabbarContainer } from './components/tabbar/container'
export { default as TabbarPanel } from './components/tabbar/panel'
// export { default as Navigator } from './components/navigator'
export { default as WebView } from './components/web-view'

0 comments on commit fd57e13

Please sign in to comment.
You can’t perform that action at this time.