Skip to content

Commit fe9b242

Browse files
authored
Merge pull request #8 from devautor/master
Updated styles to align buttons and gifs containers
2 parents 5255d82 + 442f760 commit fe9b242

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

src/GifSearch.js

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class GifSearch extends PureComponent {
8888
if (props.numColumns != null) {
8989
this.numColumns = props.numColumns;
9090
this.horizontal = false;
91-
this.gifSize = Dimensions.get('window').width / this.numColumns - 20;
91+
this.gifSize = Dimensions.get('window').width / this.numColumns - 15;
9292
}
9393
this.provider = providers.ALL;
9494
if (props.provider != null) {
@@ -352,7 +352,7 @@ class GifSearch extends PureComponent {
352352
}
353353
if (this.numColumns > 1) {
354354
Dimensions.addEventListener('change', () => {
355-
this.setState({gifSize: Dimensions.get('window').width / this.numColumns - 20})
355+
this.setState({gifSize: Dimensions.get('window').width / this.numColumns - 15})
356356
})
357357
}
358358
}
@@ -369,12 +369,13 @@ class GifSearch extends PureComponent {
369369
(
370370
<View style={[this.styles.view, this.props.style]}>
371371

372-
<View style={{flexDirection: 'row', alignSelf: 'stretch', alignItems: 'center', justifyContent: 'center' }}>
372+
{/** EDIT: input box should fill whole space */}
373+
<View style={{flexDirection: 'row', alignSelf: 'stretch', alignItems: 'center', justifyContent: 'space-between' }}>
373374
<TextInput
374375
placeholder={this.state.currentGifType == gif_types.GIF ? (this.placeholderText) : (this.stickersPlaceholderText)}
375376
placeholderTextColor={this.placeholderTextColor}
376377
autoCapitalize='none'
377-
style={[this.styles.textInput, {width: this.providerLogo == null ? '100%' : '60%'}, this.props.textInputStyle]}
378+
style={[this.styles.textInput, this.props.textInputStyle]}
378379
onChangeText={this.onSearchTermChanged}
379380
value={this.state.search_term}
380381
{...this.props.textInputProps}
@@ -383,17 +384,20 @@ class GifSearch extends PureComponent {
383384
(
384385
<Image
385386
source={this.providerLogo}
386-
style={{width: '40%', height: 50, resizeMode: 'contain'}}
387+
style={{width: '25%', height: 50, resizeMode: 'contain'}}
387388
/>
388389
)
389390
:
390391
(null)
391392
}
392393
</View>
393-
{this.gifType == gif_types.ALL ?
394+
{
395+
/** EDIT: flex: 1 results in height-stretched buttons */
396+
this.gifType == gif_types.ALL ?
394397
(
395-
<View style={{flex:1, flexDirection:'row', justifyContent:'center', paddingBottom: 5}}>
398+
<View style={{flexDirection:'row', alignItems:'center', marginVertical: 5}}>
396399

400+
{/** EDIT: margin between buttons only, not on their end-sides */}
397401
<TouchableOpacity
398402
style={this.state.currentGifType != gif_types.GIF ? ([this.styles.gifTypeButton, this.props.showGifsButtonStyle])
399403
: ([this.styles.gifTypeButton, this.props.showGifsButtonStyle, this.styles.gifTypeButtonSelected, this.props.showGifsButtonSelectedStyle])}
@@ -405,9 +409,10 @@ class GifSearch extends PureComponent {
405409
{this.showGifsButtonText}
406410
</Text>
407411
</TouchableOpacity>
412+
408413
<TouchableOpacity
409-
style={this.state.currentGifType != gif_types.STICKER ? ([this.styles.gifTypeButton, this.props.showStickersButtonStyle])
410-
: ([this.styles.gifTypeButton, this.props.showStickersButtonStyle, this.styles.gifTypeButtonSelected, this.props.showStickersButtonSelectedStyle])}
414+
style={this.state.currentGifType != gif_types.STICKER ? ([this.styles.gifTypeButton, this.styles.stickerTypeButton, this.props.showStickersButtonStyle])
415+
: ([this.styles.gifTypeButton, this.styles.stickerTypeButton, this.props.showStickersButtonStyle, this.styles.gifTypeButtonSelected, this.props.showStickersButtonSelectedStyle])}
411416
onPress={this.showStickersButtonPressed}
412417
>
413418
<Text style={this.state.currentGifType != gif_types.STICKER ? ([this.styles.gifTypeButtonText, this.props.showStickersButtonTextStyle])
@@ -424,7 +429,7 @@ class GifSearch extends PureComponent {
424429
}
425430
<FlatList
426431
onEndReached={this.loadMoreGifs}
427-
onEndReachedThreshold={0.98}
432+
onEndReachedThreshold={0.8 /** EDIT */}
428433
onScroll={this.handleScroll}
429434
keyboardShouldPersistTaps={"handled"}
430435
style={[this.styles.gifList, this.props.gifListStyle]}
@@ -435,8 +440,8 @@ class GifSearch extends PureComponent {
435440
showsHorizontalScrollIndicator={this.showScrollBar}
436441
showsVerticalScrollIndicator={this.showScrollBar}
437442
{...this.props.gifListProps}
438-
renderItem={({item}) => {
439-
443+
renderItem={({item, index}) => {
444+
// EDIT: no right margin for last image column
440445
var aspect_ratio = null;
441446
var gif_preview = null;
442447
var gif_better_quality = null;
@@ -464,7 +469,7 @@ class GifSearch extends PureComponent {
464469

465470
<Image
466471
resizeMode={'cover'}
467-
style={[this.styles.image, this.numColumns > 1 ? {width:this.state.gifSize, minHeight: this.state.gifSize, maxHeight:this.state.gifSize} : {aspectRatio: aspect_ratio ? aspect_ratio : 4/3, height: 150}, this.props.gifStyle]}
472+
style={[this.styles.image, (index+1)%this.numColumns === 0 ? this.styles.lastColumnImage : {}, this.numColumns > 1 ? {width:this.state.gifSize, minHeight: this.state.gifSize, maxHeight:this.state.gifSize} : {aspectRatio: aspect_ratio ? aspect_ratio : 4/3, height: 150}, this.props.gifStyle]}
468473
source={{uri: gif_preview}}
469474
/>
470475
</TouchableOpacity>
@@ -505,6 +510,7 @@ class GifSearch extends PureComponent {
505510
padding: 10,
506511
},
507512
textInput: {
513+
flex: 1,
508514
height: 50,
509515
fontSize: 20,
510516
paddingLeft: 10,
@@ -515,9 +521,11 @@ class GifSearch extends PureComponent {
515521
marginRight: 10,
516522
marginBottom: 10
517523
},
524+
lastColumnImage: {
525+
marginRight: 0,
526+
},
518527
gifList: {
519528
height: 160,
520-
margin: 5,
521529
marginBottom: 10,
522530
},
523531
gifTypeButton: {
@@ -526,10 +534,14 @@ class GifSearch extends PureComponent {
526534
backgroundColor: "black",
527535
borderRadius: 15,
528536
padding: 6,
529-
marginHorizontal: 4,
537+
marginRight: 2,
530538
borderColor: "black",
531539
borderWidth: 2
532540
},
541+
stickerTypeButton: {
542+
marginRight: 0,
543+
marginLeft: 2
544+
},
533545
gifTypeButtonSelected: {
534546
borderColor: "white",
535547
borderWidth: 2
@@ -546,4 +558,3 @@ class GifSearch extends PureComponent {
546558
}
547559

548560
export default GifSearch;
549-

0 commit comments

Comments
 (0)