react-native - Expo Signature - Crash onChange 内容
问题描述
我写了这段代码来获取一个人的签名:
import * as ExpoPixi from 'expo-pixi';
import React, { Component } from 'react';
import { Platform, AppState, StyleSheet, Text, View } from 'react-native';
const isAndroid = Platform.OS === 'android';
function uuidv4() {
// https://stackoverflow.com/a/2117523/4047926
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = (Math.random() * 16) | 0,
v = c == 'x' ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}
export default class App extends Component {
state = {
signature: null,
appState: AppState.currentState,
};
handleAppStateChangeAsync = nextAppState => {
if (this.state.appState.match(/inactive|background/) && nextAppState === 'active') {
if (isAndroid && this.sketch) {
this.setState({ appState: nextAppState, id: uuidv4(), lines: this.sketch.lines });
return;
}
}
this.setState({ appState: nextAppState });
};
componentDidMount() {
AppState.addEventListener('change', this.handleAppStateChangeAsync);
}
componentWillUnmount() {
AppState.removeEventListener('change', this.handleAppStateChangeAsync);
}
onChange = async () => {
const { uri } = await this.sketch.takeSnapshotAsync();
this.setState({
signature: { uri },
}, () => console.log(this.state.signature));
}
render() {
return (
<View style={{flex: 1, backgroundColor: 'white'}}>
<View style={{flex: 1, left: '5%'}}>
<ExpoPixi.Signature
ref={signature => (this.sketch = signature)}
style={styles.pad}
strokeColor={'black'}
strokeAlpha={0.5}
onChange={this.onChange}
/>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
pad: {
flex: 1,
width: '90%',
borderWidth: 0.6,
borderColor: '#b3b3b5',
borderRadius: 10,
backgroundColor: 'white'
},
});
运行这个受这个库示例启发的简单代码,我注意到borderRadius
被忽略(View
缺少角),当我尝试编写签名时应用程序崩溃。
附注:是否可以获得 pad 内容的 base64 编码版本而不是 uri?
解决方案
推荐阅读
- php - 如何在一个php中的另一个查询sq2中使用php变量(数组,从sq1返回)?
- python - Pytest跳过参数化
- javascript - 如何使用 ajax 在 Asp.net 中填充下拉列表
- apache - 在不同的 GCP 项目上运行 Apache 和 Nginx 并使用相同的域
- google-sheets - 谷歌表格:部分匹配的 vLookup
- android - 我的应用在使用BCR识别时意外退出,报错“NoSuchMethodError”
- flutter - 将 ZIP 文件发送到基于 REST 的 API,该 API 使用基于 Flutter 的移动应用程序托管在 AWS 上的 SSL TLS (https)
- java - SWT ShellEvent 源属性
- r - 避免矩形覆盖轴
- javascript - 在以下 Vue.js 方法中,对象数组没有被过滤,过滤项目中的值也没有被改变