1
1
import React , { PureComponent } from 'react' ;
2
- import { Animated , FlatList } from 'react-native' ;
3
2
import autoBindReact from 'auto-bind/react' ;
3
+ import { Animated , ScrollView } from 'react-native' ;
4
4
import _ from 'lodash' ;
5
5
import PropTypes from 'prop-types' ;
6
6
import { connectStyle } from '@shoutem/theme' ;
@@ -14,7 +14,7 @@ const AnimatedIcon = Animated.createAnimatedComponent(Icon);
14
14
15
15
const optionShape = PropTypes . shape ( {
16
16
title : PropTypes . string . isRequired ,
17
- key : PropTypes . string . isRequired ,
17
+ key : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . number ] ) . isRequired ,
18
18
} ) ;
19
19
20
20
class InlineDropDownMenu extends PureComponent {
@@ -24,6 +24,10 @@ class InlineDropDownMenu extends PureComponent {
24
24
options : PropTypes . arrayOf ( optionShape ) . isRequired ,
25
25
onOptionSelected : PropTypes . func ,
26
26
selectedOption : optionShape ,
27
+ headingStyle : PropTypes . object ,
28
+ containerStyle : PropTypes . object ,
29
+ selectedOptionContainerStyle : PropTypes . object ,
30
+ selectedOptionTextStyle : PropTypes . object ,
27
31
} ;
28
32
29
33
constructor ( props ) {
@@ -69,6 +73,7 @@ class InlineDropDownMenu extends PureComponent {
69
73
70
74
return (
71
75
< InlineDropDownMenuItem
76
+ key = { item . key }
72
77
item = { item }
73
78
isSelected = { isSelected }
74
79
index = { index }
@@ -79,18 +84,32 @@ class InlineDropDownMenu extends PureComponent {
79
84
}
80
85
81
86
render ( ) {
82
- const { style, heading, selectedOption, options } = this . props ;
87
+ const {
88
+ style,
89
+ heading,
90
+ selectedOption,
91
+ options,
92
+ headingStyle,
93
+ containerStyle,
94
+ selectedOptionContainerStyle,
95
+ selectedOptionTextStyle,
96
+ } = this . props ;
83
97
const { collapsed } = this . state ;
84
98
85
99
return (
86
100
< View >
87
101
< TouchableOpacity
88
- style = { style . container }
102
+ style = { [ style . container , containerStyle ] }
89
103
onPress = { this . handleToggleMenuPress }
90
104
>
91
- < Caption styleName = "muted md-gutter-bottom" > { heading } </ Caption >
92
- < View styleName = "space-between horizontal v-center" >
93
- < Text > { selectedOption ?. title } </ Text >
105
+ < Caption styleName = "muted md-gutter-bottom" style = { headingStyle } >
106
+ { heading }
107
+ </ Caption >
108
+ < View
109
+ styleName = "space-between horizontal v-center"
110
+ style = { selectedOptionContainerStyle }
111
+ >
112
+ < Text style = { selectedOptionTextStyle } > { selectedOption ?. title } </ Text >
94
113
< AnimatedIcon
95
114
name = "drop-down"
96
115
styleName = "md-gutter-left"
@@ -109,11 +128,14 @@ class InlineDropDownMenu extends PureComponent {
109
128
</ View >
110
129
</ TouchableOpacity >
111
130
{ collapsed && (
112
- < FlatList
131
+ < ScrollView
113
132
data = { options }
114
- renderItem = { this . renderOption }
115
133
contentContainerStyle = { style . list }
116
- />
134
+ >
135
+ { _ . map ( options , ( item , index ) =>
136
+ this . renderOption ( { item, index } ) ,
137
+ ) }
138
+ </ ScrollView >
117
139
) }
118
140
</ View >
119
141
) ;
0 commit comments