Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,25 @@ const App = () => {
}}
/>
</View>

<View style={styles.section}>
<Text style={styles.sectionTitle}>Scroll Disabled Example</Text>
<GooglePlacesTextInput
apiKey="YOUR_API_KEY_HERE"
placeHolderText="Try scrolling these results"
onPlaceSelect={(place) => {
console.log('Scroll disabled example, selected:', place);
}}
scrollEnabled={false}
nestedScrollEnabled={false}
style={{
container: {
width: '100%',
paddingHorizontal: 16,
},
}}
/>
</View>
</SafeAreaView>
);
};
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"@react-native/babel-preset": "0.78.2",
"@react-native/eslint-config": "^0.78.0",
"@release-it/conventional-changelog": "^9.0.2",
"@testing-library/react-native": "^13.2.0",
"@types/jest": "^29.5.5",
"@types/react": "^19.0.12",
"commitlint": "^19.6.1",
Expand All @@ -87,6 +88,7 @@
"react": "19.0.0",
"react-native": "0.79.3",
"react-native-builder-bob": "^0.40.11",
"react-test-renderer": "19.0.0",
"release-it": "^17.10.0",
"typescript": "^5.8.3"
},
Expand Down
8 changes: 6 additions & 2 deletions src/GooglePlacesTextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ interface GooglePlacesTextInputProps {
detailsFields?: string[];
onError?: (error: any) => void;
enableDebug?: boolean; // ✅ Add debug prop
scrollEnabled?: boolean;
nestedScrollEnabled?: boolean;
}

interface GooglePlacesTextInputRef {
Expand Down Expand Up @@ -135,6 +137,8 @@ const GooglePlacesTextInput = forwardRef<
detailsFields = [],
onError,
enableDebug = false,
scrollEnabled = true,
nestedScrollEnabled = true,
},
ref
) => {
Expand Down Expand Up @@ -578,9 +582,9 @@ const GooglePlacesTextInput = forwardRef<
keyExtractor={(item) => item.placePrediction.placeId}
keyboardShouldPersistTaps="always"
style={style.suggestionsList}
scrollEnabled
scrollEnabled={scrollEnabled}
bounces={false}
nestedScrollEnabled
nestedScrollEnabled={nestedScrollEnabled}
/>
</View>
)}
Expand Down
111 changes: 110 additions & 1 deletion src/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1 +1,110 @@
it.todo('write a test');
import { render } from '@testing-library/react-native';
import GooglePlacesTextInput from '../GooglePlacesTextInput';

// Mock the API functions
jest.mock('../services/googlePlacesApi', () => ({
fetchPlaceDetails: jest.fn(),
fetchPredictions: jest.fn(),
generateUUID: jest.fn(() => 'mock-uuid'),
isRTLText: jest.fn(() => false),
}));

const defaultProps = {
apiKey: 'test-api-key',
onPlaceSelect: jest.fn(),
};

describe('GooglePlacesTextInput', () => {
beforeEach(() => {
jest.clearAllMocks();
});

it('should render without crashing', () => {
const { toJSON } = render(<GooglePlacesTextInput {...defaultProps} />);
expect(toJSON()).toBeTruthy();
});

describe('scroll control props', () => {
it('should render with scrollEnabled=true by default', () => {
const { toJSON } = render(<GooglePlacesTextInput {...defaultProps} />);
expect(toJSON()).toBeTruthy();
});

it('should render with scrollEnabled=false', () => {
const { toJSON } = render(
<GooglePlacesTextInput {...defaultProps} scrollEnabled={false} />
);
expect(toJSON()).toBeTruthy();
});

it('should render with nestedScrollEnabled=true by default', () => {
const { toJSON } = render(<GooglePlacesTextInput {...defaultProps} />);
expect(toJSON()).toBeTruthy();
});

it('should render with nestedScrollEnabled=false', () => {
const { toJSON } = render(
<GooglePlacesTextInput {...defaultProps} nestedScrollEnabled={false} />
);
expect(toJSON()).toBeTruthy();
});

it('should render with both scroll props disabled', () => {
const { toJSON } = render(
<GooglePlacesTextInput
{...defaultProps}
scrollEnabled={false}
nestedScrollEnabled={false}
/>
);
expect(toJSON()).toBeTruthy();
});
});

describe('prop validation', () => {
it('should accept scrollEnabled as boolean', () => {
// These should not throw TypeScript or runtime errors
expect(() => {
render(
<GooglePlacesTextInput {...defaultProps} scrollEnabled={true} />
);
}).not.toThrow();

expect(() => {
render(
<GooglePlacesTextInput {...defaultProps} scrollEnabled={false} />
);
}).not.toThrow();
});

it('should accept nestedScrollEnabled as boolean', () => {
// These should not throw TypeScript or runtime errors
expect(() => {
render(
<GooglePlacesTextInput {...defaultProps} nestedScrollEnabled={true} />
);
}).not.toThrow();

expect(() => {
render(
<GooglePlacesTextInput
{...defaultProps}
nestedScrollEnabled={false}
/>
);
}).not.toThrow();
});

it('should accept both scroll control props together', () => {
expect(() => {
render(
<GooglePlacesTextInput
{...defaultProps}
scrollEnabled={true}
nestedScrollEnabled={false}
/>
);
}).not.toThrow();
});
});
});
66 changes: 63 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3061,6 +3061,26 @@ __metadata:
languageName: node
linkType: hard

"@testing-library/react-native@npm:^13.2.0":
version: 13.2.0
resolution: "@testing-library/react-native@npm:13.2.0"
dependencies:
chalk: ^4.1.2
jest-matcher-utils: ^29.7.0
pretty-format: ^29.7.0
redent: ^3.0.0
peerDependencies:
jest: ">=29.0.0"
react: ">=18.2.0"
react-native: ">=0.71"
react-test-renderer: ">=18.2.0"
peerDependenciesMeta:
jest:
optional: true
checksum: fa2f59353b27a5afea72c04296e94e597b7e20f09f7e69d5dd1693da15bdeabfdd1ba655b1e194dbf5727b9dfa92de5af06ec77484b3392aab96dab4f7c05e44
languageName: node
linkType: hard

"@tootallnate/quickjs-emscripten@npm:^0.23.0":
version: 0.23.0
resolution: "@tootallnate/quickjs-emscripten@npm:0.23.0"
Expand Down Expand Up @@ -4214,7 +4234,7 @@ __metadata:
languageName: node
linkType: hard

"chalk@npm:^4.0.0, chalk@npm:^4.1.0":
"chalk@npm:^4.0.0, chalk@npm:^4.1.0, chalk@npm:^4.1.2":
version: 4.1.2
resolution: "chalk@npm:4.1.2"
dependencies:
Expand Down Expand Up @@ -9088,7 +9108,7 @@ __metadata:
languageName: node
linkType: hard

"min-indent@npm:^1.0.1":
"min-indent@npm:^1.0.0, min-indent@npm:^1.0.1":
version: 1.0.1
resolution: "min-indent@npm:1.0.1"
checksum: bfc6dd03c5eaf623a4963ebd94d087f6f4bbbfd8c41329a7f09706b0cb66969c4ddd336abeb587bc44bc6f08e13bf90f0b374f9d71f9f01e04adc2cd6f083ef1
Expand Down Expand Up @@ -10209,6 +10229,13 @@ __metadata:
languageName: node
linkType: hard

"react-is@npm:^19.0.0":
version: 19.1.0
resolution: "react-is@npm:19.1.0"
checksum: 3eb4eac7f09bf178bdc6fa98d384f5f243b85de7c99679a88b0154ead4d818ad94386ccb00ea31ec52409ffd13299057f5ec6ca2eaec06f9f7eddc1ad4832332
languageName: node
linkType: hard

"react-native-builder-bob@npm:^0.40.11":
version: 0.40.11
resolution: "react-native-builder-bob@npm:0.40.11"
Expand Down Expand Up @@ -10254,6 +10281,7 @@ __metadata:
"@react-native/babel-preset": 0.78.2
"@react-native/eslint-config": ^0.78.0
"@release-it/conventional-changelog": ^9.0.2
"@testing-library/react-native": ^13.2.0
"@types/jest": ^29.5.5
"@types/react": ^19.0.12
commitlint: ^19.6.1
Expand All @@ -10266,6 +10294,7 @@ __metadata:
react: 19.0.0
react-native: 0.79.3
react-native-builder-bob: ^0.40.11
react-test-renderer: 19.0.0
release-it: ^17.10.0
typescript: ^5.8.3
peerDependencies:
Expand Down Expand Up @@ -10343,6 +10372,18 @@ __metadata:
languageName: node
linkType: hard

"react-test-renderer@npm:19.0.0":
version: 19.0.0
resolution: "react-test-renderer@npm:19.0.0"
dependencies:
react-is: ^19.0.0
scheduler: ^0.25.0
peerDependencies:
react: ^19.0.0
checksum: 2e1e527588c69e822b7aa25262c9f4a48161ede9cee5109b88228ecafbd91ce82f7afed176645efcba903ba5a43d05842a8229cdde220049e42a0cf679715dbc
languageName: node
linkType: hard

"react@npm:19.0.0":
version: 19.0.0
resolution: "react@npm:19.0.0"
Expand Down Expand Up @@ -10445,6 +10486,16 @@ __metadata:
languageName: node
linkType: hard

"redent@npm:^3.0.0":
version: 3.0.0
resolution: "redent@npm:3.0.0"
dependencies:
indent-string: ^4.0.0
strip-indent: ^3.0.0
checksum: fa1ef20404a2d399235e83cc80bd55a956642e37dd197b4b612ba7327bf87fa32745aeb4a1634b2bab25467164ab4ed9c15be2c307923dd08b0fe7c52431ae6b
languageName: node
linkType: hard

"redent@npm:^4.0.0":
version: 4.0.0
resolution: "redent@npm:4.0.0"
Expand Down Expand Up @@ -10861,7 +10912,7 @@ __metadata:
languageName: node
linkType: hard

"scheduler@npm:0.25.0":
"scheduler@npm:0.25.0, scheduler@npm:^0.25.0":
version: 0.25.0
resolution: "scheduler@npm:0.25.0"
checksum: b7bb9fddbf743e521e9aaa5198a03ae823f5e104ebee0cb9ec625392bb7da0baa1c28ab29cee4b1e407a94e76acc6eee91eeb749614f91f853efda2613531566
Expand Down Expand Up @@ -11471,6 +11522,15 @@ __metadata:
languageName: node
linkType: hard

"strip-indent@npm:^3.0.0":
version: 3.0.0
resolution: "strip-indent@npm:3.0.0"
dependencies:
min-indent: ^1.0.0
checksum: 18f045d57d9d0d90cd16f72b2313d6364fd2cb4bf85b9f593523ad431c8720011a4d5f08b6591c9d580f446e78855c5334a30fb91aa1560f5d9f95ed1b4a0530
languageName: node
linkType: hard

"strip-indent@npm:^4.0.0":
version: 4.0.0
resolution: "strip-indent@npm:4.0.0"
Expand Down