如何为react-native组件解决此错误“RawText必须包装在显式文本组件中”

时间:2017-07-16 08:25:18

标签: reactjs react-native react-native-android react-native-ios

When I add click event for the button it shows this error in ios simulator

renderLastSlide(index) {
  if (index === this.props.data.length - 1) {
    return (
      <Container>
        <Content>
          <Button rounded light>
            <Text>Light</Text>
            onPress={this.props.onComplete}
          </Button>
        </Content>
      </Container>
    );
  }
}

此代码导致此错误的问题是什么?

3 个答案:

答案 0 :(得分:0)

我们需要在任何元素上指定事件。

在按钮上指定onPress

<Button rounded light onPress={this.props.onComplete}>
    <Text>Light</Text>    
</Button>

答案 1 :(得分:0)

按钮外面有onPress参数,所以把它放在里面。

renderLastSlide(index) {
if (index === this.props.data.length - 1) {
  return (
    <Container>
        <Content>
            <Button rounded light onPress={this.props.onComplete}>
                <Text>Light</Text>
            </Button>
        </Content>
    </Container>
  );
}

答案 2 :(得分:0)

Hai你需要在Button内部放置onPress。

#!/usr/bin/env ruby

require "google/cloud/vision"

image_paths = [
  ...
  "./wakeupcat.jpg",
  "./cat_meme_1.jpg",
  "./cat_meme_2.jpg",
  ...
]

vision = Google::Cloud::Vision.new
length = image_paths.length

start = 0
request_count = 0
while start < length do
  last = [start + 15, length - 1].min
  current_image_paths = image_paths[start..last]
  printf "Sending %d images in the request. start: %d last: %d\n", current_image_paths.length, start, last
  result = vision.annotate *current_image_paths, labels: 1
  printf "Result: %s\n", result
  start += 16
  request_count += 1
end

printf "Made %d requests\n", request_count

如果你想使用Text组件,我认为更喜欢使用TouchableOpacity而不是Button。所以我们可以在标题上添加样式。