Skip to content

Commit 3bc9dd6

Browse files
feat: creating an example of using Select together with ScrollView (#250)
Co-authored-by: Dawid Gierdal <dawid.gierdal@mobilereality.pl>
1 parent 3c34b15 commit 3bc9dd6

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

.changeset/thick-bags-brush.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@mobile-reality/react-native-select-pro': patch
3+
---
4+
5+
creating an example of using Select together with ScrollView

apps/expo/src/constants/routes.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { RealExample } from '../examples/real-example';
1414
import { Ref } from '../examples/ref';
1515
import { RHF } from '../examples/rhf';
1616
import { ScrollToSelectedOption } from '../examples/scroll-to-selected-option';
17+
import { ScrollViewExample } from '../examples/scroll-view';
1718
import { Searchable } from '../examples/searchable';
1819
import { SearchableInModal } from '../examples/searchable-in-modal';
1920
import { SearchableWithKeyboardAvoidView } from '../examples/searchable-with-keyboard-avoid-view';
@@ -121,4 +122,8 @@ export const ROUTES = [
121122
name: 'Searchable with keyboard avoid view',
122123
screen: SearchableWithKeyboardAvoidView,
123124
},
125+
{
126+
name: 'Scroll view',
127+
screen: ScrollViewExample,
128+
},
124129
];
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import * as React from 'react';
2+
import { SafeAreaView, ScrollView, StyleSheet, Text } from 'react-native';
3+
import { Select } from '@mobile-reality/react-native-select-pro';
4+
5+
const data = [
6+
{
7+
label: 'Option 1',
8+
value: 'option1',
9+
},
10+
{
11+
label: 'Option 2',
12+
value: 'option2',
13+
},
14+
{
15+
label: 'Option 3',
16+
value: 'option3',
17+
},
18+
{
19+
label: 'Option 4',
20+
value: 'option4',
21+
},
22+
];
23+
24+
export const ScrollViewExample = () => {
25+
return (
26+
<SafeAreaView style={styles.safeArea}>
27+
<ScrollView style={styles.scrollView}>
28+
<Text style={styles.title}>
29+
When using ScrollView together with Select, there are two key things to keep in
30+
mind.
31+
</Text>
32+
33+
<Text style={styles.paragraph}>
34+
First, the SelectProvider must be placed above the ScrollView in the component
35+
hierarchy.
36+
</Text>
37+
38+
<Text style={styles.paragraph}>
39+
In our case, the SelectProvider is located in the parent component, App.
40+
</Text>
41+
42+
<Text style={styles.paragraph}>
43+
Second, it is important to ensure that SelectProvider is not duplicated across
44+
different parts of the application.
45+
</Text>
46+
47+
<Text style={styles.paragraph}>
48+
This can cause issues with calculating the position of the dropdown menu.
49+
</Text>
50+
<Select options={data} />
51+
<Text style={styles.paragraph}>Scroll View Example</Text>
52+
<Text style={styles.paragraph}>Scroll View Example</Text>
53+
<Text style={styles.paragraph}>Scroll View Example</Text>
54+
<Select options={data} />
55+
<Text style={styles.paragraph}>Scroll View Example</Text>
56+
<Text style={styles.paragraph}>Scroll View Example</Text>
57+
<Text style={styles.paragraph}>Scroll View Example</Text>
58+
<Select options={data} />
59+
<Text style={styles.paragraph}>Scroll View Example</Text>
60+
<Text style={styles.paragraph}>Scroll View Example</Text>
61+
<Text style={styles.paragraph}>Scroll View Example</Text>
62+
</ScrollView>
63+
</SafeAreaView>
64+
);
65+
};
66+
67+
const styles = StyleSheet.create({
68+
title: {
69+
fontSize: 20,
70+
fontWeight: 'bold',
71+
textAlign: 'center',
72+
},
73+
paragraph: {
74+
margin: 24,
75+
textAlign: 'center',
76+
},
77+
safeArea: {
78+
flex: 1,
79+
},
80+
scrollView: {
81+
flex: 1,
82+
padding: 25,
83+
},
84+
});

0 commit comments

Comments
 (0)