Skip to content

Commit 97a40a0

Browse files
authored
Merge pull request #402 from hossein-zare/dev-5.x
v5.1.25 PR
2 parents d2f36d6 + 58a42b5 commit 97a40a0

File tree

5 files changed

+55
-13
lines changed

5 files changed

+55
-13
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22

3-
package-lock.json
3+
package-lock.json
4+
.vscode/*

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,26 @@ We are constantly working to improve this project, help us with your donation as
2020

2121
**Donate Bitcoin**
2222
+ **Payment Address:** `bc1q7sgzww3l0fk3dyy9mzcjxdw9rla3yvhuyf0qku`
23-
![QR Code](https://user-images.githubusercontent.com/56504893/116758583-a0031300-aa25-11eb-9624-0009346d2290.png)
23+
![QR Code](https://user-images.githubusercontent.com/56504893/116758583-a0031300-aa25-11eb-9624-0009346d2290.png)
24+
25+
# Merge and Release Process
26+
27+
## Branches in use
28+
29+
### Development
30+
31+
PRs should be made against and merged into the [`dev-5.x`](https://github.com/hossein-zare/react-native-dropdown-picker) branch, which is set as the `default` branch on github.
32+
33+
### Release
34+
35+
Releases are currently made from the [`5.x`](https://github.com/hossein-zare/react-native-dropdown-picker/tree/5.x) branch.
36+
37+
## Release Process
38+
39+
To make a new release, follow these steps:
40+
41+
* Verify the development branch has all the changes desired in a release and works well
42+
* Make and merge a final PR into development branch that increments the version number in `package.json`
43+
* Make and merge a PR from the development branch to the release branch
44+
* Using the GitHub web UI, draft a new release using tag name `vx.x.x` (replace the `x` values as appropriate of course), with the release branch as the target, with release name `vx.x.x` (again, with appropriate numbers in place of `x` of course)
45+
* Verify in the GitHub Actions panel for the repository that NPM publish succeeded

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ declare module "react-native-dropdown-picker" {
188188
showArrowIcon?: boolean;
189189
showBadgeDot?: boolean;
190190
showTickIcon?: boolean;
191+
stickyHeader?: boolean;
191192
ArrowUpIconComponent?: (props: {style: StyleProp<ViewStyle>}) => JSX.Element;
192193
ArrowDownIconComponent?: (props: {style: StyleProp<ViewStyle>}) => JSX.Element;
193194
TickIconComponent?: (props: {style: StyleProp<ViewStyle>}) => JSX.Element;

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-dropdown-picker",
3-
"version": "5.1.23",
3+
"version": "5.1.25",
44
"description": "A single / multiple, categorizable, customizable, localizable and searchable item picker (drop-down) component for react native which supports both Android & iOS.",
55
"keywords": [
66
"picker",
@@ -43,9 +43,7 @@
4343
"author": "Hossein Zare",
4444
"main": "index.js",
4545
"types": "index.d.ts",
46-
"dependencies": {
47-
"react-native-gesture-handler": "*"
48-
},
46+
"dependencies": {},
4947
"peerDependencies": {
5048
"react": "*",
5149
"react-native": "*"

src/components/Picker.js

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
StyleSheet
2525
} from 'react-native';
2626

27-
const {height: WINDOW_HEIGHT} = Dimensions.get('window');
27+
const { height: WINDOW_HEIGHT } = Dimensions.get('window');
2828

2929
import Colors from '../constants/colors';
3030
import {
@@ -113,6 +113,7 @@ function Picker({
113113
showArrowIcon = true,
114114
showBadgeDot = true,
115115
showTickIcon = true,
116+
stickyHeader = false,
116117
ArrowUpIconComponent = null,
117118
ArrowDownIconComponent = null,
118119
TickIconComponent = null,
@@ -311,15 +312,33 @@ function Picker({
311312
const children = items.filter(item => item[_schema.parent] !== undefined && item[_schema.parent] !== null);
312313

313314
children.forEach((child) => {
314-
const index = items.findIndex(item => item[_schema.parent] === child[_schema.parent] || item[_schema.value] === child[_schema.parent]);
315+
const index = sortedItems.findIndex(item => item[_schema.parent] === child[_schema.parent] || item[_schema.value] === child[_schema.parent]);
315316

316317
if (index > -1) {
317318
sortedItems.splice(index + 1, 0, child);
318319
}
319320
});
320321

321322
return sortedItems;
322-
}, [items, _schema])
323+
}, [items, _schema]);
324+
325+
/**
326+
* The indices of all parent items.
327+
* @returns {object}
328+
*/
329+
const stickyHeaderIndices = useMemo(() => {
330+
const stickyHeaderIndices = [];
331+
if (stickyHeader) {
332+
const parents = sortedItems.filter(item => item[_schema.parent] === undefined || item[_schema.parent] === null);
333+
parents.forEach((parent) => {
334+
const index = sortedItems.findIndex(item => item[_schema.value] === parent[_schema.value]);
335+
if (index > -1) stickyHeaderIndices.push(index);
336+
})
337+
338+
}
339+
return stickyHeaderIndices;
340+
341+
}, [stickyHeader, sortedItems])
323342

324343
/**
325344
* The items.
@@ -526,7 +545,6 @@ function Picker({
526545
open,
527546
onPressToggle,
528547
onPress,
529-
pickerRef,
530548
maxHeight,
531549
pickerHeight,
532550
bottomOffset,
@@ -982,7 +1000,8 @@ function Picker({
9821000
*/
9831001
const _listItemContainerStyle = useMemo(() => ([
9841002
RTL_DIRECTION(rtl, THEME.listItemContainer),
985-
...[listItemContainerStyle].flat()
1003+
...[listItemContainerStyle].flat(),
1004+
stickyHeader && {backgroundColor: THEME.style.backgroundColor},
9861005
]), [rtl, listItemContainerStyle, THEME]);
9871006

9881007
/**
@@ -1465,6 +1484,7 @@ function Picker({
14651484
keyExtractor={keyExtractor}
14661485
extraData={_value}
14671486
ItemSeparatorComponent={ItemSeparatorComponent}
1487+
stickyHeaderIndices={stickyHeaderIndices}
14681488
{...flatListProps}
14691489
/>
14701490
), [
@@ -1484,7 +1504,7 @@ function Picker({
14841504
*/
14851505
const DropDownScrollViewComponent = useMemo(() => {
14861506
return (
1487-
<ScrollView nestedScrollEnabled={true} {...scrollViewProps}>
1507+
<ScrollView nestedScrollEnabled={true} stickyHeaderIndices={stickyHeaderIndices} {...scrollViewProps} >
14881508
{_items.map((item, index) => {
14891509
return (
14901510
<Fragment key={item[_itemKey]}>
@@ -1570,4 +1590,4 @@ const styles = StyleSheet.create({
15701590
}
15711591
});
15721592

1573-
export default memo(Picker);
1593+
export default memo(Picker);

0 commit comments

Comments
 (0)