Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RN] Optional use TouchableWithoutFeedback component in Flex/FlexItem component #2095

Merged
merged 3 commits into from Nov 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -22,19 +22,6 @@ exports[`renders ./components/activity-indicator/demo/basic.native.tsx correctly
}
>
<View
accessibilityComponentType={undefined}
accessibilityLabel={undefined}
accessibilityTraits={undefined}
accessible={true}
hitSlop={undefined}
nativeID={undefined}
onLayout={undefined}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Array [
Object {
Expand All @@ -46,22 +33,8 @@ exports[`renders ./components/activity-indicator/demo/basic.native.tsx correctly
undefined,
]
}
testID={undefined}
>
<View
accessibilityComponentType={undefined}
accessibilityLabel={undefined}
accessibilityTraits={undefined}
accessible={true}
hitSlop={undefined}
nativeID={undefined}
onLayout={undefined}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Array [
Object {
Expand All @@ -70,7 +43,6 @@ exports[`renders ./components/activity-indicator/demo/basic.native.tsx correctly
undefined,
]
}
testID={undefined}
>
<Text
accessible={true}
Expand All @@ -82,19 +54,6 @@ exports[`renders ./components/activity-indicator/demo/basic.native.tsx correctly
</Text>
</View>
<View
accessibilityComponentType={undefined}
accessibilityLabel={undefined}
accessibilityTraits={undefined}
accessible={true}
hitSlop={undefined}
nativeID={undefined}
onLayout={undefined}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Array [
Object {
Expand All @@ -103,7 +62,6 @@ exports[`renders ./components/activity-indicator/demo/basic.native.tsx correctly
undefined,
]
}
testID={undefined}
>
<View
style={
Expand Down Expand Up @@ -148,19 +106,6 @@ exports[`renders ./components/activity-indicator/demo/basic.native.tsx correctly
}
>
<View
accessibilityComponentType={undefined}
accessibilityLabel={undefined}
accessibilityTraits={undefined}
accessible={true}
hitSlop={undefined}
nativeID={undefined}
onLayout={undefined}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Array [
Object {
Expand All @@ -172,22 +117,8 @@ exports[`renders ./components/activity-indicator/demo/basic.native.tsx correctly
undefined,
]
}
testID={undefined}
>
<View
accessibilityComponentType={undefined}
accessibilityLabel={undefined}
accessibilityTraits={undefined}
accessible={true}
hitSlop={undefined}
nativeID={undefined}
onLayout={undefined}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Array [
Object {
Expand All @@ -196,7 +127,6 @@ exports[`renders ./components/activity-indicator/demo/basic.native.tsx correctly
undefined,
]
}
testID={undefined}
>
<Text
accessible={true}
Expand All @@ -208,19 +138,6 @@ exports[`renders ./components/activity-indicator/demo/basic.native.tsx correctly
</Text>
</View>
<View
accessibilityComponentType={undefined}
accessibilityLabel={undefined}
accessibilityTraits={undefined}
accessible={true}
hitSlop={undefined}
nativeID={undefined}
onLayout={undefined}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Array [
Object {
Expand All @@ -229,7 +146,6 @@ exports[`renders ./components/activity-indicator/demo/basic.native.tsx correctly
undefined,
]
}
testID={undefined}
>
<View
style={
Expand Down Expand Up @@ -291,19 +207,6 @@ exports[`renders ./components/activity-indicator/demo/basic.native.tsx correctly
}
>
<View
accessibilityComponentType={undefined}
accessibilityLabel={undefined}
accessibilityTraits={undefined}
accessible={true}
hitSlop={undefined}
nativeID={undefined}
onLayout={undefined}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Array [
Object {
Expand All @@ -315,22 +218,8 @@ exports[`renders ./components/activity-indicator/demo/basic.native.tsx correctly
undefined,
]
}
testID={undefined}
>
<View
accessibilityComponentType={undefined}
accessibilityLabel={undefined}
accessibilityTraits={undefined}
accessible={true}
hitSlop={undefined}
nativeID={undefined}
onLayout={undefined}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Array [
Object {
Expand All @@ -339,7 +228,6 @@ exports[`renders ./components/activity-indicator/demo/basic.native.tsx correctly
undefined,
]
}
testID={undefined}
>
<Text
accessible={true}
Expand All @@ -351,19 +239,6 @@ exports[`renders ./components/activity-indicator/demo/basic.native.tsx correctly
</Text>
</View>
<View
accessibilityComponentType={undefined}
accessibilityLabel={undefined}
accessibilityTraits={undefined}
accessible={true}
hitSlop={undefined}
nativeID={undefined}
onLayout={undefined}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Array [
Object {
Expand All @@ -372,7 +247,6 @@ exports[`renders ./components/activity-indicator/demo/basic.native.tsx correctly
undefined,
]
}
testID={undefined}
>
<View
style={
Expand Down Expand Up @@ -431,19 +305,6 @@ exports[`renders ./components/activity-indicator/demo/basic.native.tsx correctly
}
>
<View
accessibilityComponentType={undefined}
accessibilityLabel={undefined}
accessibilityTraits={undefined}
accessible={true}
hitSlop={undefined}
nativeID={undefined}
onLayout={undefined}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Array [
Object {
Expand All @@ -455,22 +316,8 @@ exports[`renders ./components/activity-indicator/demo/basic.native.tsx correctly
undefined,
]
}
testID={undefined}
>
<View
accessibilityComponentType={undefined}
accessibilityLabel={undefined}
accessibilityTraits={undefined}
accessible={true}
hitSlop={undefined}
nativeID={undefined}
onLayout={undefined}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Array [
Object {
Expand All @@ -479,7 +326,6 @@ exports[`renders ./components/activity-indicator/demo/basic.native.tsx correctly
undefined,
]
}
testID={undefined}
>
<Text
accessible={true}
Expand All @@ -491,19 +337,6 @@ exports[`renders ./components/activity-indicator/demo/basic.native.tsx correctly
</Text>
</View>
<View
accessibilityComponentType={undefined}
accessibilityLabel={undefined}
accessibilityTraits={undefined}
accessible={true}
hitSlop={undefined}
nativeID={undefined}
onLayout={undefined}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Array [
Object {
Expand All @@ -512,7 +345,6 @@ exports[`renders ./components/activity-indicator/demo/basic.native.tsx correctly
undefined,
]
}
testID={undefined}
>
<View
style={
Expand Down
38 changes: 30 additions & 8 deletions components/flex/Flex.native.tsx
Expand Up @@ -20,9 +20,17 @@ export default class Flex extends React.Component<FlexProps, any> {
};

render() {
let { style, direction, wrap, justify, align, children, ...restProps } = this.props;
let {
style,
direction,
wrap,
justify,
align,
children,
...restProps,
} = this.props;
let transferConst = [justify, align];
transferConst = transferConst.map((el) => {
transferConst = transferConst.map(el => {
let tempTxt;
switch (el) {
case 'start':
Expand Down Expand Up @@ -51,12 +59,26 @@ export default class Flex extends React.Component<FlexProps, any> {
alignItems: transferConst[1],
};

return (
<TouchableWithoutFeedback {...restProps}>
<View style={[flexStyle, style]}>
{children}
</View>
</TouchableWithoutFeedback>
const inner = (
<View style={[flexStyle, style]} {...restProps}>
{children}
</View>
);

const shouldWrapInTouchableComponent =
restProps.onPress ||
restProps.onLongPress ||
restProps.onPressIn ||
restProps.onPressOut;

if (!!shouldWrapInTouchableComponent) {
return (
<TouchableWithoutFeedback {...restProps}>
{inner}
</TouchableWithoutFeedback>
);
} else {
return inner;
}
}
}