Skip to content

Commit 503be03

Browse files
authored
Merge pull request #13 from AntonioRoye/feat--exposing-scroll-control-props
feat: add scrollEnabled and nestedScrollEnabled props to control FlatList scrolling
2 parents 49a0122 + 4405968 commit 503be03

File tree

5 files changed

+200
-6
lines changed

5 files changed

+200
-6
lines changed

example/App.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,25 @@ const App = () => {
138138
}}
139139
/>
140140
</View>
141+
142+
<View style={styles.section}>
143+
<Text style={styles.sectionTitle}>Scroll Disabled Example</Text>
144+
<GooglePlacesTextInput
145+
apiKey="YOUR_API_KEY_HERE"
146+
placeHolderText="Try scrolling these results"
147+
onPlaceSelect={(place) => {
148+
console.log('Scroll disabled example, selected:', place);
149+
}}
150+
scrollEnabled={false}
151+
nestedScrollEnabled={false}
152+
style={{
153+
container: {
154+
width: '100%',
155+
paddingHorizontal: 16,
156+
},
157+
}}
158+
/>
159+
</View>
141160
</SafeAreaView>
142161
);
143162
};

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
"@react-native/babel-preset": "0.78.2",
7676
"@react-native/eslint-config": "^0.78.0",
7777
"@release-it/conventional-changelog": "^9.0.2",
78+
"@testing-library/react-native": "^13.2.0",
7879
"@types/jest": "^29.5.5",
7980
"@types/react": "^19.0.12",
8081
"commitlint": "^19.6.1",
@@ -87,6 +88,7 @@
8788
"react": "19.0.0",
8889
"react-native": "0.79.3",
8990
"react-native-builder-bob": "^0.40.11",
91+
"react-test-renderer": "19.0.0",
9092
"release-it": "^17.10.0",
9193
"typescript": "^5.8.3"
9294
},

src/GooglePlacesTextInput.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ interface GooglePlacesTextInputProps {
9595
detailsFields?: string[];
9696
onError?: (error: any) => void;
9797
enableDebug?: boolean; // ✅ Add debug prop
98+
scrollEnabled?: boolean;
99+
nestedScrollEnabled?: boolean;
98100
}
99101

100102
interface GooglePlacesTextInputRef {
@@ -135,6 +137,8 @@ const GooglePlacesTextInput = forwardRef<
135137
detailsFields = [],
136138
onError,
137139
enableDebug = false,
140+
scrollEnabled = true,
141+
nestedScrollEnabled = true,
138142
},
139143
ref
140144
) => {
@@ -578,9 +582,9 @@ const GooglePlacesTextInput = forwardRef<
578582
keyExtractor={(item) => item.placePrediction.placeId}
579583
keyboardShouldPersistTaps="always"
580584
style={style.suggestionsList}
581-
scrollEnabled
585+
scrollEnabled={scrollEnabled}
582586
bounces={false}
583-
nestedScrollEnabled
587+
nestedScrollEnabled={nestedScrollEnabled}
584588
/>
585589
</View>
586590
)}

src/__tests__/index.test.tsx

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,110 @@
1-
it.todo('write a test');
1+
import { render } from '@testing-library/react-native';
2+
import GooglePlacesTextInput from '../GooglePlacesTextInput';
3+
4+
// Mock the API functions
5+
jest.mock('../services/googlePlacesApi', () => ({
6+
fetchPlaceDetails: jest.fn(),
7+
fetchPredictions: jest.fn(),
8+
generateUUID: jest.fn(() => 'mock-uuid'),
9+
isRTLText: jest.fn(() => false),
10+
}));
11+
12+
const defaultProps = {
13+
apiKey: 'test-api-key',
14+
onPlaceSelect: jest.fn(),
15+
};
16+
17+
describe('GooglePlacesTextInput', () => {
18+
beforeEach(() => {
19+
jest.clearAllMocks();
20+
});
21+
22+
it('should render without crashing', () => {
23+
const { toJSON } = render(<GooglePlacesTextInput {...defaultProps} />);
24+
expect(toJSON()).toBeTruthy();
25+
});
26+
27+
describe('scroll control props', () => {
28+
it('should render with scrollEnabled=true by default', () => {
29+
const { toJSON } = render(<GooglePlacesTextInput {...defaultProps} />);
30+
expect(toJSON()).toBeTruthy();
31+
});
32+
33+
it('should render with scrollEnabled=false', () => {
34+
const { toJSON } = render(
35+
<GooglePlacesTextInput {...defaultProps} scrollEnabled={false} />
36+
);
37+
expect(toJSON()).toBeTruthy();
38+
});
39+
40+
it('should render with nestedScrollEnabled=true by default', () => {
41+
const { toJSON } = render(<GooglePlacesTextInput {...defaultProps} />);
42+
expect(toJSON()).toBeTruthy();
43+
});
44+
45+
it('should render with nestedScrollEnabled=false', () => {
46+
const { toJSON } = render(
47+
<GooglePlacesTextInput {...defaultProps} nestedScrollEnabled={false} />
48+
);
49+
expect(toJSON()).toBeTruthy();
50+
});
51+
52+
it('should render with both scroll props disabled', () => {
53+
const { toJSON } = render(
54+
<GooglePlacesTextInput
55+
{...defaultProps}
56+
scrollEnabled={false}
57+
nestedScrollEnabled={false}
58+
/>
59+
);
60+
expect(toJSON()).toBeTruthy();
61+
});
62+
});
63+
64+
describe('prop validation', () => {
65+
it('should accept scrollEnabled as boolean', () => {
66+
// These should not throw TypeScript or runtime errors
67+
expect(() => {
68+
render(
69+
<GooglePlacesTextInput {...defaultProps} scrollEnabled={true} />
70+
);
71+
}).not.toThrow();
72+
73+
expect(() => {
74+
render(
75+
<GooglePlacesTextInput {...defaultProps} scrollEnabled={false} />
76+
);
77+
}).not.toThrow();
78+
});
79+
80+
it('should accept nestedScrollEnabled as boolean', () => {
81+
// These should not throw TypeScript or runtime errors
82+
expect(() => {
83+
render(
84+
<GooglePlacesTextInput {...defaultProps} nestedScrollEnabled={true} />
85+
);
86+
}).not.toThrow();
87+
88+
expect(() => {
89+
render(
90+
<GooglePlacesTextInput
91+
{...defaultProps}
92+
nestedScrollEnabled={false}
93+
/>
94+
);
95+
}).not.toThrow();
96+
});
97+
98+
it('should accept both scroll control props together', () => {
99+
expect(() => {
100+
render(
101+
<GooglePlacesTextInput
102+
{...defaultProps}
103+
scrollEnabled={true}
104+
nestedScrollEnabled={false}
105+
/>
106+
);
107+
}).not.toThrow();
108+
});
109+
});
110+
});

yarn.lock

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3061,6 +3061,26 @@ __metadata:
30613061
languageName: node
30623062
linkType: hard
30633063

3064+
"@testing-library/react-native@npm:^13.2.0":
3065+
version: 13.2.0
3066+
resolution: "@testing-library/react-native@npm:13.2.0"
3067+
dependencies:
3068+
chalk: ^4.1.2
3069+
jest-matcher-utils: ^29.7.0
3070+
pretty-format: ^29.7.0
3071+
redent: ^3.0.0
3072+
peerDependencies:
3073+
jest: ">=29.0.0"
3074+
react: ">=18.2.0"
3075+
react-native: ">=0.71"
3076+
react-test-renderer: ">=18.2.0"
3077+
peerDependenciesMeta:
3078+
jest:
3079+
optional: true
3080+
checksum: fa2f59353b27a5afea72c04296e94e597b7e20f09f7e69d5dd1693da15bdeabfdd1ba655b1e194dbf5727b9dfa92de5af06ec77484b3392aab96dab4f7c05e44
3081+
languageName: node
3082+
linkType: hard
3083+
30643084
"@tootallnate/quickjs-emscripten@npm:^0.23.0":
30653085
version: 0.23.0
30663086
resolution: "@tootallnate/quickjs-emscripten@npm:0.23.0"
@@ -4214,7 +4234,7 @@ __metadata:
42144234
languageName: node
42154235
linkType: hard
42164236

4217-
"chalk@npm:^4.0.0, chalk@npm:^4.1.0":
4237+
"chalk@npm:^4.0.0, chalk@npm:^4.1.0, chalk@npm:^4.1.2":
42184238
version: 4.1.2
42194239
resolution: "chalk@npm:4.1.2"
42204240
dependencies:
@@ -9088,7 +9108,7 @@ __metadata:
90889108
languageName: node
90899109
linkType: hard
90909110

9091-
"min-indent@npm:^1.0.1":
9111+
"min-indent@npm:^1.0.0, min-indent@npm:^1.0.1":
90929112
version: 1.0.1
90939113
resolution: "min-indent@npm:1.0.1"
90949114
checksum: bfc6dd03c5eaf623a4963ebd94d087f6f4bbbfd8c41329a7f09706b0cb66969c4ddd336abeb587bc44bc6f08e13bf90f0b374f9d71f9f01e04adc2cd6f083ef1
@@ -10209,6 +10229,13 @@ __metadata:
1020910229
languageName: node
1021010230
linkType: hard
1021110231

10232+
"react-is@npm:^19.0.0":
10233+
version: 19.1.0
10234+
resolution: "react-is@npm:19.1.0"
10235+
checksum: 3eb4eac7f09bf178bdc6fa98d384f5f243b85de7c99679a88b0154ead4d818ad94386ccb00ea31ec52409ffd13299057f5ec6ca2eaec06f9f7eddc1ad4832332
10236+
languageName: node
10237+
linkType: hard
10238+
1021210239
"react-native-builder-bob@npm:^0.40.11":
1021310240
version: 0.40.11
1021410241
resolution: "react-native-builder-bob@npm:0.40.11"
@@ -10254,6 +10281,7 @@ __metadata:
1025410281
"@react-native/babel-preset": 0.78.2
1025510282
"@react-native/eslint-config": ^0.78.0
1025610283
"@release-it/conventional-changelog": ^9.0.2
10284+
"@testing-library/react-native": ^13.2.0
1025710285
"@types/jest": ^29.5.5
1025810286
"@types/react": ^19.0.12
1025910287
commitlint: ^19.6.1
@@ -10266,6 +10294,7 @@ __metadata:
1026610294
react: 19.0.0
1026710295
react-native: 0.79.3
1026810296
react-native-builder-bob: ^0.40.11
10297+
react-test-renderer: 19.0.0
1026910298
release-it: ^17.10.0
1027010299
typescript: ^5.8.3
1027110300
peerDependencies:
@@ -10343,6 +10372,18 @@ __metadata:
1034310372
languageName: node
1034410373
linkType: hard
1034510374

10375+
"react-test-renderer@npm:19.0.0":
10376+
version: 19.0.0
10377+
resolution: "react-test-renderer@npm:19.0.0"
10378+
dependencies:
10379+
react-is: ^19.0.0
10380+
scheduler: ^0.25.0
10381+
peerDependencies:
10382+
react: ^19.0.0
10383+
checksum: 2e1e527588c69e822b7aa25262c9f4a48161ede9cee5109b88228ecafbd91ce82f7afed176645efcba903ba5a43d05842a8229cdde220049e42a0cf679715dbc
10384+
languageName: node
10385+
linkType: hard
10386+
1034610387
"react@npm:19.0.0":
1034710388
version: 19.0.0
1034810389
resolution: "react@npm:19.0.0"
@@ -10445,6 +10486,16 @@ __metadata:
1044510486
languageName: node
1044610487
linkType: hard
1044710488

10489+
"redent@npm:^3.0.0":
10490+
version: 3.0.0
10491+
resolution: "redent@npm:3.0.0"
10492+
dependencies:
10493+
indent-string: ^4.0.0
10494+
strip-indent: ^3.0.0
10495+
checksum: fa1ef20404a2d399235e83cc80bd55a956642e37dd197b4b612ba7327bf87fa32745aeb4a1634b2bab25467164ab4ed9c15be2c307923dd08b0fe7c52431ae6b
10496+
languageName: node
10497+
linkType: hard
10498+
1044810499
"redent@npm:^4.0.0":
1044910500
version: 4.0.0
1045010501
resolution: "redent@npm:4.0.0"
@@ -10861,7 +10912,7 @@ __metadata:
1086110912
languageName: node
1086210913
linkType: hard
1086310914

10864-
"scheduler@npm:0.25.0":
10915+
"scheduler@npm:0.25.0, scheduler@npm:^0.25.0":
1086510916
version: 0.25.0
1086610917
resolution: "scheduler@npm:0.25.0"
1086710918
checksum: b7bb9fddbf743e521e9aaa5198a03ae823f5e104ebee0cb9ec625392bb7da0baa1c28ab29cee4b1e407a94e76acc6eee91eeb749614f91f853efda2613531566
@@ -11471,6 +11522,15 @@ __metadata:
1147111522
languageName: node
1147211523
linkType: hard
1147311524

11525+
"strip-indent@npm:^3.0.0":
11526+
version: 3.0.0
11527+
resolution: "strip-indent@npm:3.0.0"
11528+
dependencies:
11529+
min-indent: ^1.0.0
11530+
checksum: 18f045d57d9d0d90cd16f72b2313d6364fd2cb4bf85b9f593523ad431c8720011a4d5f08b6591c9d580f446e78855c5334a30fb91aa1560f5d9f95ed1b4a0530
11531+
languageName: node
11532+
linkType: hard
11533+
1147411534
"strip-indent@npm:^4.0.0":
1147511535
version: 4.0.0
1147611536
resolution: "strip-indent@npm:4.0.0"

0 commit comments

Comments
 (0)