react-native-sketch模块和组件根本不工作

时间:2017-08-22 21:20:40

标签: javascript xcode react-native

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);

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

1 个答案:

答案 0 :(得分:0)

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