加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
SignatureCapture.js 2.97 KB
一键复制 编辑 原始数据 按行查看 历史
niantuo 提交于 2019-06-30 22:31 . 为什么会有以前的接口
'use strict';
var ReactNative = require('react-native');
var React = require('react');
var PropTypes = require('prop-types');
var {
requireNativeComponent,
View,
UIManager,
DeviceEventEmitter
} = ReactNative;
class SignatureCapture extends React.Component {
constructor() {
super();
this.onChange = this.onChange.bind(this);
this.subscriptions = [];
}
onChange(event) {
if (event.nativeEvent.pathName) {
if (!this.props.onSaveEvent) {
return;
}
this.props.onSaveEvent({
pathName: event.nativeEvent.pathName,
encoded: event.nativeEvent.encoded,
});
}
if (event.nativeEvent.dragged) {
if (!this.props.onDragEvent) {
return;
}
this.props.onDragEvent({
dragged: event.nativeEvent.dragged
});
}
}
componentDidMount() {
if (this.props.onSaveEvent) {
let sub = DeviceEventEmitter.addListener(
'onSaveEvent',
this.props.onSaveEvent
);
this.subscriptions.push(sub);
}
if (this.props.onDragEvent) {
let sub = DeviceEventEmitter.addListener(
'onDragEvent',
this.props.onDragEvent
);
this.subscriptions.push(sub);
}
}
componentWillUnmount() {
this.subscriptions.forEach(sub => sub.remove());
this.subscriptions = [];
}
render() {
return (
<RSSignatureView {...this.props} onChange={this.onChange}/>
);
}
getViewManagerConfig = (
viewManagerName
) => {
if (!UIManager.getViewManagerConfig) {
return UIManager[viewManagerName];
}
return UIManager.getViewManagerConfig(viewManagerName);
};
saveImage() {
UIManager.dispatchViewManagerCommand(
ReactNative.findNodeHandle(this),
this.getViewManagerConfig('RSSignatureView').Commands.saveImage,
[],
);
}
resetImage() {
UIManager.dispatchViewManagerCommand(
ReactNative.findNodeHandle(this),
this.getViewManagerConfig('RSSignatureView').Commands.resetImage,
[],
);
}
}
SignatureCapture.propTypes = {
...View.propTypes,
rotateClockwise: PropTypes.bool,
square: PropTypes.bool,
saveImageFileInExtStorage: PropTypes.bool,
viewMode: PropTypes.string,
showBorder: PropTypes.bool,
showNativeButtons: PropTypes.bool,
showTitleLabel: PropTypes.bool,
maxSize: PropTypes.number,
minStrokeWidth: PropTypes.number,
maxStrokeWidth: PropTypes.number,
strokeColor: PropTypes.string,
backgroundColor: PropTypes.string
};
var RSSignatureView = requireNativeComponent('RSSignatureView', SignatureCapture, {
nativeOnly: {onChange: true}
});
module.exports = SignatureCapture;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化