Skip to content

Commit 772b82a

Browse files
committed
fix: center icon in button along with text
1 parent 85cb5bd commit 772b82a

File tree

9 files changed

+44
-51
lines changed

9 files changed

+44
-51
lines changed

docs/assets/screenshots/button-1.png

2.83 KB
Loading

docs/assets/screenshots/button-2.png

8.01 KB
Loading

docs/assets/screenshots/button-3.png

4.36 KB
Loading
-2.35 KB
Binary file not shown.
-2.22 KB
Binary file not shown.
-2.31 KB
Binary file not shown.

example/assets/favorite.png

482 Bytes
Loading

example/src/ButtonExample.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class ButtonExample extends React.Component<Props, State> {
8585
</Button>
8686
<Button
8787
raised
88-
icon={require('../assets/chameleon.jpg')}
88+
icon={require('../assets/favorite.png')}
8989
onPress={() => {}}
9090
>
9191
Required asset

src/components/Button.js

+43-50
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ type State = {
7070
* A button is component that the user can press to trigger an action.
7171
*
7272
* <div class="screenshots">
73-
* <img src="http://github.com/screenshots/button-%3Cspan%20class="x x-first x-last">raised.png" />
74-
* <img src="http://github.com/screenshots/button-%3Cspan%20class="x x-first x-last">primary.png" />
75-
* <img src="http://github.com/screenshots/button-%3Cspan%20class="x x-first x-last">custom.png" />
73+
* <img src="http://github.com/screenshots/button-%3Cspan%20class="x x-first x-last">1.png" />
74+
* <img src="http://github.com/screenshots/button-%3Cspan%20class="x x-first x-last">2.png" />
75+
* <img src="http://github.com/screenshots/button-%3Cspan%20class="x x-first x-last">3.png" />
7676
* </div>
7777
*
7878
* ## Usage
@@ -185,37 +185,6 @@ class Button extends React.Component<Props, State> {
185185
const textStyle = { color: textColor, fontFamily };
186186
const elevation = disabled ? 0 : this.state.elevation;
187187

188-
const content = (
189-
<View style={styles.content}>
190-
{icon && loading !== true ? (
191-
<View style={styles.icon}>
192-
<Icon name={icon} size={16} color={textColor} />
193-
</View>
194-
) : null}
195-
{loading ? (
196-
<ActivityIndicator
197-
size="small"
198-
color={textColor}
199-
style={styles.icon}
200-
/>
201-
) : null}
202-
<Text
203-
numberOfLines={1}
204-
style={[
205-
styles.label,
206-
compact && styles.compactLabel,
207-
textStyle,
208-
{ fontFamily },
209-
]}
210-
>
211-
{React.Children.map(
212-
children,
213-
child => (typeof child === 'string' ? child.toUpperCase() : child)
214-
)}
215-
</Text>
216-
</View>
217-
);
218-
219188
return (
220189
<AnimatedPaper
221190
style={[
@@ -226,21 +195,45 @@ class Button extends React.Component<Props, State> {
226195
style,
227196
]}
228197
>
229-
{disabled ? (
230-
content
231-
) : (
232-
<TouchableRipple
233-
borderless
234-
delayPressIn={0}
235-
onPress={onPress}
236-
onPressIn={this._handlePressIn}
237-
onPressOut={this._handlePressOut}
238-
rippleColor={rippleColor}
239-
style={touchableStyle}
240-
>
241-
{content}
242-
</TouchableRipple>
243-
)}
198+
<TouchableRipple
199+
borderless
200+
delayPressIn={0}
201+
onPress={disabled ? undefined : onPress}
202+
onPressIn={disabled ? undefined : this._handlePressIn}
203+
onPressOut={disabled ? undefined : this._handlePressOut}
204+
rippleColor={rippleColor}
205+
style={touchableStyle}
206+
>
207+
<View style={styles.content}>
208+
{icon && loading !== true ? (
209+
<View style={styles.icon}>
210+
<Icon name={icon} size={16} color={textColor} />
211+
</View>
212+
) : null}
213+
{loading ? (
214+
<ActivityIndicator
215+
size="small"
216+
color={textColor}
217+
style={styles.icon}
218+
/>
219+
) : null}
220+
<Text
221+
numberOfLines={1}
222+
style={[
223+
styles.label,
224+
compact && styles.compactLabel,
225+
textStyle,
226+
{ fontFamily },
227+
]}
228+
>
229+
{React.Children.map(
230+
children,
231+
child =>
232+
typeof child === 'string' ? child.toUpperCase() : child
233+
)}
234+
</Text>
235+
</View>
236+
</TouchableRipple>
244237
</AnimatedPaper>
245238
);
246239
}
@@ -257,7 +250,7 @@ const styles = StyleSheet.create({
257250
content: {
258251
flexDirection: 'row',
259252
alignItems: 'center',
260-
justifyContent: 'space-around',
253+
justifyContent: 'center',
261254
},
262255
icon: {
263256
width: 16,

0 commit comments

Comments
 (0)