Skip to content

Commit 5adc148

Browse files
committed
fix: webview ref issue
1 parent 9ae556f commit 5adc148

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

lib/webview.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import WebView from 'react-native-webview';
44
import PropTypes from 'prop-types';
55
import LoadingBar from "./loading-bar";
66

7-
export default class ProgressBarWebView extends React.PureComponent {
7+
class ProgressBarWebView extends React.PureComponent {
88

99
static propTypes = {
1010
height: PropTypes.number,
@@ -61,12 +61,13 @@ export default class ProgressBarWebView extends React.PureComponent {
6161
}
6262

6363
render() {
64-
const { height } = this.props;
64+
const { height, forwardedRef } = this.props;
6565
const { percent, color, visible } = this.state;
6666
return (
6767
<View style={styles.container}>
6868
{visible && <LoadingBar height={height} color={color} percent={percent}/>}
6969
<WebView
70+
ref={forwardedRef}
7071
onLoadStart={this._onLoadStart}
7172
onLoadEnd={this._onLoadEnd}
7273
onLoadProgress={this._onLoadProgress}
@@ -84,3 +85,7 @@ const styles = StyleSheet.create({
8485
position: 'relative',
8586
},
8687
});
88+
89+
export default React.forwardRef((props, ref) => (
90+
<ProgressBarWebView {...props} forwardedRef={ref}/>
91+
));

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "react-native-progress-webview",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "React Native Progress WebView is a wrapper of React Native WebView to provide the loading status.",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "jest"
88
},
99
"keywords": [
1010
"react",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`LoadingBar Rendering should match to snapshot 1`] = `ShallowWrapper {}`;

test/loading-bar.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react';
2+
import {shallow} from 'enzyme';
3+
import LoadingBar from '../lib/loading-bar';
4+
5+
describe('LoadingBar', () => {
6+
describe('Rendering', () => {
7+
it('should match to snapshot', () => {
8+
const component = shallow(<LoadingBar />);
9+
expect(component).toMatchSnapshot()
10+
});
11+
});
12+
});

0 commit comments

Comments
 (0)