-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hoà Phan
authored and
Hoà Phan
committed
Feb 26, 2023
1 parent
0139fd0
commit e383c18
Showing
3 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import React, { useRef, useState } from 'react'; | ||
import { StyleSheet, Dimensions, View, Text } from 'react-native'; | ||
import { Dropdown, IDropdownRef } from 'react-native-element-dropdown'; | ||
|
||
const data = [ | ||
{ label: 'Item 1', value: '1' }, | ||
{ label: 'Item 2', value: '2' }, | ||
{ label: 'Item 3', value: '3' }, | ||
{ label: 'Item 4', value: '4' }, | ||
{ label: 'Item 5', value: '5' }, | ||
{ label: 'Item 6', value: '6' }, | ||
{ label: 'Item 7', value: '7' }, | ||
{ label: 'Item 8', value: '8' }, | ||
]; | ||
|
||
const { width } = Dimensions.get('window'); | ||
|
||
const DropdownComponent = () => { | ||
const [value, setValue] = useState<string>(); | ||
const ref = useRef<IDropdownRef>(null); | ||
|
||
const renderIcon = () => { | ||
return ( | ||
<View style={styles.iconStyle}> | ||
<Text>Icon</Text> | ||
</View> | ||
); | ||
}; | ||
|
||
return ( | ||
<Dropdown | ||
ref={ref} | ||
statusBarIsTranslucent={true} | ||
style={styles.dropdown} | ||
containerStyle={styles.containerStyle} | ||
iconStyle={styles.iconStyle} | ||
data={data} | ||
maxHeight={300} | ||
labelField="label" | ||
valueField="value" | ||
value={value} | ||
onChange={(item) => { | ||
setValue(item.value); | ||
}} | ||
onChangeText={() => {}} // Keep search keyword | ||
renderRightIcon={renderIcon} | ||
/> | ||
); | ||
}; | ||
|
||
export default DropdownComponent; | ||
|
||
const styles = StyleSheet.create({ | ||
dropdown: { | ||
margin: 16, | ||
width: 50, | ||
marginLeft: width - 80, | ||
height: 50, | ||
borderColor: 'gray', | ||
borderWidth: 0.5, | ||
borderRadius: 8, | ||
paddingRight: 14, | ||
}, | ||
containerStyle: { | ||
width: 200, | ||
marginLeft: -150, | ||
marginTop: 5, | ||
}, | ||
iconStyle: { | ||
width: 50, | ||
height: 50, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}, | ||
}); |