Skip to content

Commit 935b2f1

Browse files
committed
fix: package.json and readme file updated
1 parent 7d3f85b commit 935b2f1

File tree

2 files changed

+71
-56
lines changed

2 files changed

+71
-56
lines changed

README.md

Lines changed: 70 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -21,74 +21,89 @@ Then, if you didn't install `react-native-linear-gradient` before: Enter command
2121
#Basic usage
2222

2323
```
24-
import React from 'react';
25-
import {View, Text, Dimensions} from 'react-native';
24+
import React, { useState } from 'react';
25+
import { Dimensions, StyleSheet, Text, View } from 'react-native';
2626
2727
import DynamicallySelectedPicker from 'react-native-dynamically-selected-picker';
2828
29-
export default class Example extends React.Component {
30-
state = {
31-
selectedItemIndex: 0,
32-
};
33-
34-
updateSelectedItem(index) {
35-
this.setState({selectedItemIndex: index});
36-
}
37-
38-
render() {
39-
const windowWidth = Dimensions.get('window').width;
40-
41-
return (
42-
<View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
43-
<DynamicallySelectedPicker
44-
items={[
45-
{
46-
value: 1,
47-
label: 'Item 1',
48-
},
49-
{
50-
value: 2,
51-
label: 'Item 2',
52-
},
53-
{
54-
value: 3,
55-
label: 'Item 3',
56-
},
57-
{
58-
value: 4,
59-
label: 'Item 4',
60-
},
61-
{
62-
value: 5,
63-
label: 'Item 5',
64-
},
65-
]}
66-
onScroll={({index, item}) => {
67-
this.updateSelectedItem(index);
68-
}}
69-
height={300}
70-
width={windowWidth}
71-
/>
72-
<View style={{marginTop: 50}}>
73-
<Text>Selected item index {this.state.selectedItemIndex}</Text>
74-
</View>
29+
export default function App() {
30+
const [selectedItemIndex, setSelectedItemIndex] = useState<number>(0);
31+
const initialSelectedIndex = 1;
32+
const windowWidth = Dimensions.get('window').width;
33+
const height = 300;
34+
35+
return (
36+
<View style={styles.container}>
37+
<DynamicallySelectedPicker
38+
items={[
39+
{
40+
value: 1,
41+
label: 'Item 1',
42+
},
43+
{
44+
value: 2,
45+
label: 'Item 2',
46+
},
47+
{
48+
value: 3,
49+
label: 'Item 3',
50+
},
51+
{
52+
value: 4,
53+
label: 'Item 4',
54+
itemColor: 'blue',
55+
},
56+
{
57+
value: 5,
58+
label: 'Item 5',
59+
},
60+
]}
61+
onScroll={({ index }) => setSelectedItemIndex(index)}
62+
onMomentumScrollBegin={({ index }) => setSelectedItemIndex(index)}
63+
onMomentumScrollEnd={({ index }) => setSelectedItemIndex(index)}
64+
onScrollBeginDrag={({ index }) => setSelectedItemIndex(index)}
65+
onScrollEndDrag={({ index }) => setSelectedItemIndex(index)}
66+
initialSelectedIndex={initialSelectedIndex}
67+
height={height}
68+
width={windowWidth}
69+
/>
70+
<View style={styles.selectedItemWrapper}>
71+
<Text>Selected item index {selectedItemIndex}</Text>
7572
</View>
76-
);
77-
}
73+
</View>
74+
);
7875
}
7976
77+
const styles = StyleSheet.create({
78+
container: {
79+
flex: 1,
80+
alignItems: 'center',
81+
justifyContent: 'center',
82+
},
83+
box: {
84+
width: 60,
85+
height: 60,
86+
marginVertical: 20,
87+
},
88+
gradientWrapper: {
89+
position: 'absolute',
90+
width: '100%',
91+
},
92+
selectedItemWrapper: { marginTop: 50 },
93+
});
94+
8095
```
8196

8297
## Properties
8398

8499
| Prop | Default | Type | Description |
85100
| :------------- | :-------------: | :------: | :---------------------------------------------------------------------------------------------------------- |
86101
| items | [{value: 0, label: 'No items', itemColor: 'black'}] | `Array<object>` | - |
87-
| onScroll | - | `func` | Returns selected item object and selected index |
88-
| onMomentumScrollBegin | - | `func` | Returns selected item object and selected index |
89-
| onMomentumScrollEnd | - | `func` | Returns selected item object and selected index |
90-
| onScrollBeginDrag | - | `func` | Returns selected item object and selected index |
91-
| onScrollEndDrag | - | `func` | Returns selected item object and selected index |
102+
| onScroll | - | `func` | Returns selected selected index |
103+
| onMomentumScrollBegin | - | `func` | Returns selected selected index |
104+
| onMomentumScrollEnd | - | `func` | Returns selected selected index |
105+
| onScrollBeginDrag | - | `func` | Returns selected selected index |
106+
| onScrollEndDrag | - | `func` | Returns selected selected index |
92107
| initialSelectedIndex | 0 | `number` | Set index number of initial item. |
93108
| transparentItemRows | 3 | `number` | Set number of items at top and bottom of selected index. |
94109
| width | 300 | `number` | - |

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-native-dynamically-selected-picker",
33
"version": "3.0.0",
4-
"description": "test",
4+
"description": "React Native Custom Picker for Android and IOS with onScroll change selected items",
55
"main": "lib/commonjs/index.js",
66
"module": "lib/module/index.js",
77
"types": "lib/typescript/src/index.d.ts",

0 commit comments

Comments
 (0)