diff --git a/index.d.ts b/index.d.ts index 4c8c3790..50621112 100644 --- a/index.d.ts +++ b/index.d.ts @@ -265,6 +265,7 @@ declare module 'react-native-dropdown-picker' { testID?: string; closeOnBackPressed?: boolean; hideSelectedItemIcon?: boolean; + extendableBadgeContainer?: boolean; } interface DropDownPickerSingleProps { diff --git a/package.json b/package.json index 1846f418..9472e79e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-dropdown-picker", - "version": "5.3.0", + "version": "5.4.0-beta.0", "description": "A single / multiple, categorizable, customizable, localizable and searchable item picker (drop-down) component for react native which supports both Android & iOS.", "keywords": [ "picker", diff --git a/src/components/Picker.js b/src/components/Picker.js index 4dba6072..6ddf29b6 100644 --- a/src/components/Picker.js +++ b/src/components/Picker.js @@ -158,6 +158,7 @@ function Picker({ theme = THEMES.DEFAULT, testID, closeOnBackPressed = false, + extendableBadgeContainer = false, onSelectItem = (item) => {} }) { const [necessaryItems, setNecessaryItems] = useState([]); @@ -1039,10 +1040,10 @@ function Picker({ ), [_badgeSeparatorStyle]); /** - * The label container. + * The label container style. * @returns {object} */ - const labelContainer = useMemo(() => ([ + const labelContainerStyle = useMemo(() => ([ THEME.labelContainer, rtl && { transform: [ {scaleX: -1} @@ -1055,12 +1056,12 @@ function Picker({ * @returns {JSX.Element} */ const BadgeListEmptyComponent = useCallback(() => ( - + {_placeholder} - ), [_labelStyle, labelContainer, labelProps, _placeholder]); + ), [_labelStyle, labelContainerStyle, labelProps, _placeholder]); /** * Set ref. @@ -1069,26 +1070,73 @@ function Picker({ badgeFlatListRef.current = ref; }, []); + /** + * The extendable badge container style. + * @returns {object} + */ + const extendableBadgeContainerStyle = useMemo(() => ([ + RTL_DIRECTION(rtl, THEME.extendableBadgeContainer) + ]), [rtl, THEME]); + + /** + * The extendable badge item container style. + * @returns {object} + */ + const extendableBadgeItemContainerStyle = useMemo(() => ([ + THEME.extendableBadgeItemContainer, rtl && { + marginEnd: 0, + marginStart: THEME.extendableBadgeItemContainer.marginEnd + } + ]), [rtl, THEME]); + + /** + * Extendable badge container. + * @returns {JSX.Element} + */ + const ExtendableBadgeContainer = useCallback(({selectedItems}) => { + if (selectedItems.length > 0) { + return ( + + {selectedItems.map((item, index) => ( + + <__renderBadge item={item} /> + + ))} + + ); + } + + return ; + }, [__renderBadge, extendableBadgeContainerStyle, extendableBadgeItemContainerStyle]); + /** * The badge body component. * @returns {JSX.Element} */ - const BadgeBodyComponent = useMemo(() => ( - - ), [ + const BadgeBodyComponent = useMemo(() => { + if (extendableBadgeContainer) { + return + } + + return ( + + ); + }, [ rtl, + extendableBadgeContainer, + ExtendableBadgeContainer, selectedItems, __renderBadge, keyExtractor, @@ -1765,4 +1813,4 @@ const styles = StyleSheet.create({ } }); -export default memo(Picker); +export default memo(Picker); \ No newline at end of file diff --git a/src/themes/dark/index.js b/src/themes/dark/index.js index e19831b9..1d778d9a 100644 --- a/src/themes/dark/index.js +++ b/src/themes/dark/index.js @@ -20,11 +20,12 @@ export default StyleSheet.create({ alignItems: 'center', justifyContent: 'space-between', width: '100%', - height: 50, + minHeight: 50, borderRadius: 8, borderWidth: 1, borderColor: Colors.BLACK, paddingHorizontal: 10, + paddingVertical: 3, backgroundColor: Colors.EBONY_CLAY, }, label: { @@ -170,5 +171,14 @@ export default StyleSheet.create({ modalTitle: { fontSize: 18, color: Colors.HEATHER + }, + extendableBadgeContainer: { + flexDirection: 'row', + flexWrap: 'wrap', + flex: 1 + }, + extendableBadgeItemContainer: { + marginVertical: 3, + marginEnd: 7 } }); diff --git a/src/themes/light/index.js b/src/themes/light/index.js index 4186419a..ba38795c 100644 --- a/src/themes/light/index.js +++ b/src/themes/light/index.js @@ -20,11 +20,12 @@ export default StyleSheet.create({ alignItems: 'center', justifyContent: 'space-between', width: '100%', - height: 50, + minHeight: 50, borderRadius: 8, borderWidth: 1, borderColor: Colors.BLACK, paddingHorizontal: 10, + paddingVertical: 3, backgroundColor: Colors.WHITE }, label: { @@ -169,5 +170,14 @@ export default StyleSheet.create({ modalTitle: { fontSize: 18, color: Colors.BLACK + }, + extendableBadgeContainer: { + flexDirection: 'row', + flexWrap: 'wrap', + flex: 1 + }, + extendableBadgeItemContainer: { + marginVertical: 3, + marginEnd: 7 } }); \ No newline at end of file