Skip to content

Commit 51732ae

Browse files
Kaishley Lingachettimastermoo
authored andcommitted
Refactor common code.
1 parent 7e355c0 commit 51732ae

File tree

3 files changed

+5
-30
lines changed

3 files changed

+5
-30
lines changed

ActionButton.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { Component, PropTypes } from 'react';
22
import { StyleSheet, Text, View, Animated, TouchableOpacity, TouchableNativeFeedback, Platform } from 'react-native';
33
import ActionButtonItem from './ActionButtonItem';
4-
import { shadowStyle, alignItemsMap, Touchable, isAndroid } from './shared';
4+
import { shadowStyle, alignItemsMap, Touchable, isAndroid, touchableBackground } from './shared';
55

66
export default class ActionButton extends Component {
77
constructor(props) {
@@ -104,15 +104,6 @@ export default class ActionButton extends Component {
104104
justifyContent: 'center',
105105
}
106106

107-
var touchableBackground;
108-
if (isAndroid) {
109-
if (Platform['Version'] >= 21) {
110-
touchableBackground = TouchableNativeFeedback.Ripple('rgba(255,255,255,0.75)');
111-
} else {
112-
touchableBackground = TouchableNativeFeedback.SelectableBackground();
113-
}
114-
}
115-
116107
return (
117108
<View style={{ paddingHorizontal: this.props.offsetX }}>
118109
<Touchable

ActionButtonItem.js

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { Component, PropTypes } from 'react';
22
import { StyleSheet, Text, View, Animated,
33
TouchableNativeFeedback, TouchableWithoutFeedback, Dimensions, Platform } from 'react-native';
4-
import { shadowStyle, alignItemsMap, Touchable, isAndroid } from './shared';
4+
import { shadowStyle, alignItemsMap, Touchable, isAndroid, touchableBackground } from './shared';
55

66
const { width: WIDTH } = Dimensions.get('window');
77
const SHADOW_SPACE = 10;
@@ -55,15 +55,6 @@ export default class ActionButtonItem extends Component {
5555

5656
if (position !== 'center') buttonStyle[position] = (this.props.parentSize-size)/2;
5757

58-
var touchableBackground;
59-
if (isAndroid) {
60-
if (Platform['Version'] >= 21) {
61-
touchableBackground = TouchableNativeFeedback.Ripple('rgba(255,255,255,0.75)');
62-
} else {
63-
touchableBackground = TouchableNativeFeedback.SelectableBackground();
64-
}
65-
}
66-
6758
return (
6859
<Animated.View pointerEvents="box-none" style={animatedViewStyle}>
6960
<Touchable
@@ -96,15 +87,6 @@ export default class ActionButtonItem extends Component {
9687

9788
const textStyles = [styles.textContainer, positionStyles, textContainerStyle, !hideShadow && shadowStyle];
9889

99-
var touchableBackground;
100-
if (isAndroid) {
101-
if (Platform['Version'] >= 21) {
102-
touchableBackground = TouchableNativeFeedback.Ripple('rgba(255,255,255,0.75)');
103-
} else {
104-
touchableBackground = TouchableNativeFeedback.SelectableBackground();
105-
}
106-
}
107-
10890
return (
10991
<TextTouchable
11092
background={touchableBackground}

shared.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ export const alignItemsMap = {
1919

2020
export const Touchable = Platform.OS === 'ios' ? TouchableOpacity : TouchableNativeFeedback;
2121

22-
export const isAndroid = Platform.OS === 'android';
22+
export const isAndroid = Platform.OS === 'android';
23+
24+
export const touchableBackground = isAndroid ? Platform['Version'] >= 21 ? TouchableNativeFeedback.Ripple('rgba(255,255,255,0.75)') : TouchableNativeFeedback.SelectableBackground() : undefined;

0 commit comments

Comments
 (0)