react-native - 如何将反应原生签名画布功能组件转换为类组件
问题描述
我是新来的反应本地人。我不知道如何将功能组件转换为类组件。请帮忙。这是我在功能组件中的本机签名画布代码的代码我想将其转换为类组件,请帮助谢谢。
const ref = useRef();
const handleSignature = signature => {
const path = FileSystem.cacheDirectory + 'sign.png';
FileSystem.writeAsStringAsync(path, signature.replace('data:image/png;base64,', ''), {encoding: FileSystem.EncodingType.Base64}).then(res => {
// console.log(res);
// FileSystem.getInfoAsync(path, {size: true, md5: true}).then(file => {
FileSystem.getInfoAsync(path).then(file => {
console.log(file);
setSingleFileSIGN({ singleFileSIGN: file.uri});
console.log(singleFileSIGN)
})
}).catch(err => {
console.log("err", err);
})
};
const handleEmpty = () => {
console.log('Empty');
};
const handleClear = () => {
console.log('clear success!');
};
const handleEnd = () => {
ref.current.readSignature();
};
<View style={{flex: 1, width:355,
...Platform.select({
android: {
marginBottom:-80,
borderColor: '#FF8C00',
borderWidth:1
// marginBottom:-150
},
}),
}}>
<SignatureScreen style={{height: '400%'}}
ref={ref}
onEnd={handleEnd}
onOK={handleSignature}
onEmpty={handleEmpty}
onClear={handleClear}
descriptionText={'Sign here!'}
/>
</View>
解决方案
const signatureRef = createRef()
clearSignature = async () => {
await signatureRef.current?.clearSignature()
}
handleOK = async (signature) => {
const sign = signature.split(",").pop()
await this.setState({
signatureVal: sign
})
// onOK(signature); // Callback from Component props
};
handleEnd = async () => {
await this.setState({isScrollEnabled: true})
await signatureRef.current?.readSignature()
}
render(){
<View>
<SignatureScreen
ref={signatureRef}
onOK={this.handleOK}
onEnd={this.handleEnd}
androidHardwareAccelerationDisabled={true}
onBegin={async () => {await this.setState({
isScrollEnabled: false
})}}
/>
</View>
}
推荐阅读
- javascript - Var中的Mapbox多个If语句
- php - 高级自定义字段日期选择器数据在自定义 wordpress 后循环中使用时会出错
- python - 使用 Abseil 与直接调用 main()?
- .net-core - 如何将 DI 代码集中在 lambda function.cs 之外,而是集中到专用类中以更好地分离关注点
- java - RSA 加密 Java/Kotlin
- tabulator - 如何将子菜单添加到制表符上下文菜单?
- java - 使 export JAVA_HOME=`/usr/libexec/java_home -v 1.8` 永久化
- html - 用另一个数组中的一个数组填充表 *ngFor
- debugging - 在 Visual Studio 代码中调试 Blazor webasm
- html - 如何设置背景颜色的宽度等于标题标签的宽度?