【问题标题】:react-native-sketch module and component not working at allreact-native-sketch 模块和组件根本不工作
【发布时间】:2017-08-22 21:20:40
【问题描述】:
import React, { Component } from 'react';
import {
  AppRegistry,
  Button,
  StyleSheet,
  View,
  requireNativeComponent,
} from 'react-native';
import Sketch from 'react-native-sketch';


const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  sketch: {
    height: 250, // Height needed; Default: 200px
  },
});

export default class paintChalledgeNative extends Component {
  constructor(props) {
    super(props);
    this.clear = this.clear.bind(this);
    this.onReset = this.onReset.bind(this);
    this.onSave = this.onSave.bind(this);
    this.onUpdate = this.onUpdate.bind(this);
    this.state = {
      drawing: null,
    };
  }


  onReset() {
    console.log('bye bye drawing');
  }


  onSave() {
    this.sketch.saveImage(this.state.drawing)
      .then(data => console.log(data))
      .catch(error => console.log(error));
  }

  onUpdate(base64Image) {
    this.setState({ drawing: base64Image });
  }
  clear() {
    this.sketch.clear();
  }


  render() {
    return (
      <View style={styles.container}>
        <Sketch
          fillColor="transparent"
          strokeColor="#111111"
          strokeThickness={2}
          imageType="png"
          onReset={this.onReset}
          onUpdate={this.onUpdate}
          ref={(sketch) => { this.sketch = sketch; }}
          style={styles.sketch}
        />
        <Button
          onPress={this.clear}
          title="clear drawing"
        />
        <Button
          disabled={!this.state.encodedSignature}
          onPress={this.onSave}
          title="Save drawing"
        />

      </View>
    );
  }
}


AppRegistry.registerComponent('paintChalledgeNative', () => paintChalledgeNative);

使用“react-native-sketch”构建草图应用程序,模拟器正在运行,但草图功能根本没有工作,清除按钮使应用程序崩溃并出现图像错误,控制台正在记录 20 个类似的错误消息下面的那个 '在 /Users/waltershub/Desktop/paintChalledgeNative/node_modules/react-native-sketch/RNSketch/RNSketch.m:11 中包含的文件中: ../react-native/React/Base/RCTEventDispatcher.h:18:3:错误:重新定义枚举器“RCTTextEventTypeChange” RCTTextEventTypeChange,'

【问题讨论】:

    标签: javascript xcode react-native


    【解决方案1】:

    我认为这是因为您使用了 0.5 版本的 react-native-sketch,它与 React Native > 0.40 不兼容。从那时起,一个新的1.0 版本has been published,所以也许你可以再试一次? (免责声明:我是 react-native-sketch 的维护者)

    【讨论】:

      猜你喜欢
      • 2021-12-06
      • 1970-01-01
      • 2021-03-29
      • 2017-01-21
      • 1970-01-01
      • 1970-01-01
      • 2018-07-26
      • 1970-01-01
      • 2019-08-07
      相关资源
      最近更新 更多