forked from zzz945/react-native-alibc-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
84 lines (72 loc) · 2.06 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import React, { Component, PureComponent } from 'react';
import PropTypes from 'prop-types'
import {
View,
Button,
UIManager,
NativeModules,
requireNativeComponent,
findNodeHandle,
} from 'react-native';
const ALIBC_TRADEWEBVIEW_REF = 'ALIBCTRADEWEBVIEW_REF';
export class AlibcTradeWebView extends React.Component {
constructor(props) {
super(props);
this._onTradeResult = this._onTradeResult.bind(this);
this._onStateChange = this._onStateChange.bind(this);
this.goForward = this.goForward.bind(this);
this.goBack = this.goBack.bind(this);
this.reload = this.reload.bind(this);
this._getWebViewBridgeHandle = this._getWebViewBridgeHandle.bind(this);
}
_onTradeResult(event) {
if (!this.props.onTradeResult) {
return;
}
this.props.onTradeResult(event.nativeEvent);
}
_onStateChange(event) {
if (!this.props.onStateChange) {
return;
}
this.props.onStateChange(event.nativeEvent);
}
goForward() {
UIManager.dispatchViewManagerCommand(
this._getWebViewBridgeHandle(),
UIManager.RCTWebViewBridge.Commands.goForward,
null
);
}
goBack() {
UIManager.dispatchViewManagerCommand(
this._getWebViewBridgeHandle(),
UIManager.AlibcTradeWebView.Commands.goBack,
null
);
}
reload() {
UIManager.dispatchViewManagerCommand(
this._getWebViewBridgeHandle(),
UIManager.RCTWebViewBridge.Commands.reload,
null
);
}
_getWebViewBridgeHandle() {
return findNodeHandle(this.refs[ALIBC_TRADEWEBVIEW_REF]);
}
render() {
return <NativeComponent ref={ALIBC_TRADEWEBVIEW_REF} {...this.props}
onTradeResult={this._onTradeResult}
onStateChange={this._onStateChange}/>;
}
}
AlibcTradeWebView.propTypes = {
param: PropTypes.object,
onTradeResult: PropTypes.func,
onStateChange: PropTypes.func,
...View.propTypes,
};
const NativeComponent = requireNativeComponent("AlibcTradeWebView", AlibcTradeWebView);
const { RNAlibcSdk } = NativeModules;
export default RNAlibcSdk;