【发布时间】:2017-12-06 10:34:45
【问题描述】:
我正在尝试使用 Flow 对我的 React Native 项目进行类型注释,但我无法找到 Text 和 TouchableOpacity 元素的类型定义,因此我可以引用它们的 style 道具类型定义。如何导入和/或引用这些元素的类型定义?
代码如下:
// @flow
import * as React from "react";
import { Text, TouchableOpacity } from "react-native";
type Props = {
segmentIndex: number,
segmentInfo: {
title: string
},
segmentStyle: ???, // WHAT SHOULD I USE HERE?
titleStyle: ???, // WHAT SHOULD I USE HERE?
onSelection: (number) => void
}
export const SegmentButton = (props: Props) => {
const _segmentPressed = () => {
props.onSelection(props.segmentIndex)
}
return (
<TouchableOpacity style={props.segmentStyle} onPress={_segmentPressed}>
<Text style={props.titleStyle}>{props.segmentInfo.title.charAt(0).toUpperCase() + props.segmentInfo.title.substring(1)}</Text>
</TouchableOpacity>
)
}
【问题讨论】:
标签: react-native flowtype