react-native-dialer-code-picker v1.0.2
react-native-dialer-code-picker โกโกโก
This library offers a multi-language country dialer code picker with advanced search functionality, delivering a smooth and high-performance user experience. Designed to be fully cross-platform, it supports React Native and Expo out of the box.
๐ Built for Performance: Enhanced with optimized rendering and efficient animations for seamless navigation using FlashList.
๐ Issue-Free Experience: Developed with careful attention to detail, addressing common issues found in similar libraries.
๐ Flexible & Customizable: Easily adaptable to your design needs with custom templates and styling options.
Inspired by the popular
react-native-country-codes-picker
, but enhanced with better performance and stability. If you're looking for a modern alternative with optimized rendering and customization capabilities, this is the picker for you.
Looking for a specific country or locale? Feel free to contribute with a PR. โกโกโก
๐ Installation
You can install it using npm or yarn:
# Using npm
npm install react-native-dialer-code-picker @shopify/flash-list
# Using yarn
yarn add react-native-dialer-code-picker @shopify/flash-list
Note: This library uses
FlashList
from@shopify/flash-list
for improved performance, so make sure to install it as a dependency.
โ๏ธ Basic Usage
Using DialerPicker
(Built-in Modal)
The DialerPicker
component includes a built-in modal, so you can directly use it without handling modal logic manually.
import React, { useState } from 'react';
import { View, Button, Text } from 'react-native';
import { DialerPicker } from 'react-native-dialer-code-picker';
const App = () => {
const [isVisible, setIsVisible] = useState(false);
const [selectedDialer, setSelectedDialer] = useState('');
const handleDialerSelect = (item) => {
setSelectedDialer(item.dial_code);
setIsVisible(false);
};
return (
<View>
<Button title="Select Dialer Code" onPress={() => setIsVisible(true)} />
<Text>Selected Dialer Code: {selectedDialer}</Text>
<DialerPicker
isVisible={isVisible}
onDialCodeSelect={handleDialerSelect}
onClose={() => setIsVisible(false)}
searchPlaceholder="Search by country or code"
lang="en"
/>
</View>
);
};
export default App;
๐ก Advanced Usage
Using DialerList
(Custom Modal or Bottom Sheet)
If you want to use your own modal (e.g., BottomSheetModal
), you can import DialerList
and handle the modal separately.
import React, { useState, useCallback } from 'react';
import { View, Button } from 'react-native';
import { DialerList } from 'react-native-dialer-code-picker';
import {
BottomSheetModal,
BottomSheetModalProvider,
} from '@gorhom/bottom-sheet';
const BottomSheetDialer = () => {
const [bottomSheetRef, setBottomSheetRef] = useState(null);
const openSheet = useCallback(() => {
bottomSheetRef?.present();
}, [bottomSheetRef]);
return (
<BottomSheetModalProvider>
<View>
<Button title="Open Dialer" onPress={openSheet} />
<BottomSheetModal
ref={setBottomSheetRef}
index={0}
snapPoints={['50%']}
>
<DialerList
onDialCodeSelect={(item) => {
console.log(item.dial_code);
bottomSheetRef?.dismiss();
}}
lang="en"
/>
</BottomSheetModal>
</View>
</BottomSheetModalProvider>
);
};
Comparison: DialerPicker
vs. DialerList
Feature | DialerPicker (Built-in Modal) | DialerList (Standalone) |
---|---|---|
Includes a modal? | โ Yes | โ No |
Manages its own state? | โ Yes | โ No |
Custom modal support? | โ No, uses default modal | โ Yes |
Ideal for...? | Quick implementation | Full customization |
๐ Props and API Details
DialerPicker Props
Prop | Type | Description | Required | Default |
---|---|---|---|---|
isVisible | boolean | Controls the visibility of the modal. | โ | false |
enableModalAvoiding | boolean | Enables keyboard avoiding behavior on Android. | โ | false |
disableBackdrop | boolean | If true , disables the backdrop behind the modal. | โ | false |
androidWindowSoftInputMode | string | Defines keyboard behavior on Android (e.g., "pan" ). | โ | - |
searchPlaceholder | string | Placeholder text for the search input. | โ | "Search..." |
searchPlaceholderTextColor | string | Color of the placeholder text in the search input field. | โ | - |
searchNotFoundMessage | string | Message displayed when no results are found. | โ | - |
lang | string | Selected language for country names. | โ | "en" |
defaultDialCode | string | Default dial code to be pre-selected. | โ | - |
otherCountriesHeaderTitle | string | Title for the "Other Countries" section. | โ | - |
searchContainerStyle | StyleProp<ViewStyle> | Custom styles for the search input container. | โ | - |
excludedCountries | string[] | List of country codes to exclude from the picker. | โ | [] |
showOnly | string[] | List of country codes to exclusively show. | โ | [] |
popularCountries | string[] | List of popular countries to show at the top. | โ | [] |
onDialCodeSelect | (item: DialerCode) => void | Callback when a dialer code is selected. | โ | - |
onBackdropPress | () => void | Callback when the backdrop is pressed. | โ | - |
onClose | () => void | Callback when the modal is closed. | โ | - |
itemTemplate | (props: DialerItemTemplateProps) => JSX.Element | Custom template to render each item. | โ | DialerButton |
headerComponent | (props: DialerListHeaderComponentProps) => JSX.Element | Custom component for the list header. | โ | - |
style | DialerStyle | Style object to customize the picker. | โ | - |
showVerticalScrollIndicator | boolean | Whether to show the vertical scroll indicator. Default is false . | โ | false |
DialerList Props
Prop | Type | Description | Required | Default |
---|---|---|---|---|
excludedCountries | string[] | List of country codes to exclude. | โ | [] |
showOnly | string[] | List of country codes to exclusively show. | โ | [] |
popularCountries | string[] | List of popular country codes displayed at the top. | โ | [] |
onDialCodeSelect | (item: DialerCode) => void | Callback triggered when a dial code is selected. | โ | - |
lang | string | Language code for country names. | โ | "en" |
headerComponent | (props: DialerListHeaderComponentProps) => JSX.Element | Custom component for the list header. | โ | - |
itemTemplate | (props: DialerItemTemplateProps) => JSX.Element | Custom component for rendering each item. | โ | DialerButton |
style | DialerStyle | Style object to customize the component. | โ | - |
searchContainerStyle | StyleProp<ViewStyle> | Custom styles for the search container. | โ | - |
showVerticalScrollIndicator | boolean | Whether to show the vertical scroll indicator. Default is false . | โ | false |
searchValue | string | Text input for filtering countries by name or dial code. | โ | - |
๐ License
This project is licensed under the MIT License.
See the LICENSE file for more details.
๐ค Contributions
Contributions are welcome!
If you find a bug or want to add a new feature, please open an Issue or a Pull Request.