2.0.2 ā€¢ Published 1 year ago

react-native-paginated-modal-picker v2.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Single and Multiple React Native Modal Picker With Pagination!

Install

npm i react-native-paginated-modal-picker

Single and Multi Picker Usage

import React, { useState, useEffect } from 'react';
import { View, Text, Dimensions, Image } from 'react-native';
import {
  PaginatedModalPicker,
  PaginatedMultipleModalPicker,
} from 'react-native-paginated-modal-picker';
import axios from 'axios';
const { width, height } = Dimensions.get('window');
export default function App() {
  const [users, setUsers] = useState({
    data: [],
    pageNumber: 1,
    isLoading: false,
  });

  const pages = 2;
  const [selectedUser, setSelectedUser] = useState({
    name: '',
    id: '',
  });

  const [selectedUsers, setSelectedUsers] = useState({
    names: [],
    ids: [],
  });

  const getCountriesData = async (page) => {
    const response = await axios.get(
      `https://reqres.in/api/users?page=${page}`,
      {
        headers: {
          'Content-Type': 'application/json',
        },
      }
    );

    return response.data.data;
  };

  useEffect(() => {
    getCountriesData(users.pageNumber).then((response) => {
      const usersLabeled = response.map((data) =>
        Object.assign({}, { label: data.first_name, value: data.id })
      );
      setUsers({
        ...users,
        data: [...users.data, ...usersLabeled],
        isLoading: false,
      });
    });
  }, [users.pageNumber]);

  return (
    <View
      style={{ flex: 1, alignItems: 'center', justifyContent: 'space-around' }}>
      <PaginatedModalPicker
        textInputStyle={{ paddingLeft: 5 }}
        // modalStyle={{ height: height * 0.4 }}
        flatListStyle={{ padding: 6 }}
        listItemStyle={{
          borderRadius: 5,
          borderColor: 'black',
          borderWidth: 0.4,
          marginTop: 20,
        }}
        listItemTextStyle={{ color: 'blue' }}
        placeholderTextColor='#9b9b9b'
        placeholder={'Select a User'}
        isRequestingComponent={<Text>Loading Component</Text>}
        ListEmptyComponent={<Text>Empty Component</Text>}
        isWorking={true}
        data={users.data}
        // modalType={'FullScreen'}
        backDropOpacity={0.6}
        onSelect={(item) => {
          setSelectedUser({ id: item.value, name: item.label });
        }}
        value={selectedUser.name}
        onEndReached={() =>
          pages > users.pageNumber &&
          setUsers({
            ...users,
            pageNumber: users.pageNumber + 1,
            isLoading: true,
          })
        }
        isRequesting={users.isLoading}
        onEndReachedThreshold={0}
      />

      <PaginatedMultipleModalPicker
        textInputStyle={{ paddingLeft: 5 }}
        // modalStyle={{ height: height * 0.4 }}
        flatListStyle={{ padding: 6 }}
        listItemStyle={{
          borderRadius: 5,
          borderColor: 'black',
          borderWidth: 0.4,
          marginTop: 20,
        }}
        listItemTextStyle={{ color: 'blue' }}
        //new props start
        saveButtonStyle={{ backgroundColor: '#1259a1' }}
        saveButtonTitleStyle={{ fontSize: 17 }}
        saveButtonTitle='Confirm'
        selectedItemImageStyle={{ width: 13, height: 13 }}
        selectedItemIconComponent={
          <Image
            source={require('./images/correct.png')}
            style={{ height: 20, width: 20 }}
          />
        }
        //new props end
        placeholderTextColor='#9b9b9b'
        placeholder={'Select Multiple Users'}
        isRequestingComponent={<Text>Loading Component</Text>}
        ListEmptyComponent={<Text>Empty Component</Text>}
        isWorking={true}
        data={users.data}
        // modalType={'FullScreen'}
        backDropOpacity={0.6}
        onSelect={(item) => {
          setSelectedUsers({ ids: item.values, names: item.labels });
        }}
        value={selectedUsers?.names?.toString()}
        onEndReached={() =>
          pages > users.pageNumber &&
          setUsers({
            ...users,
            pageNumber: users.pageNumber + 1,
            isLoading: true,
          })
        }
        isRequesting={users.isLoading}
        onEndReachedThreshold={0}
      />
    </View>
  );
}

Properties

Single Picker

Props

PropDefaultTypeDescription
data[{label:'', value:''}]arrayan array pagination items
placeholderClick Me!stringplace holder for textinput
isWorkingtrueboolenable/disable textinput
isRequestingfalseboolshows flatlist footer component when requesting data with pagination
onSelectcall back functionused to get the selected label and value
valuestringvalue of text input after onSelect is fired
modalTypeCustomstringwhen modalType is 'FullScreen' it become in fullscreen view
onEndReachedfunctiontriggered when end of flatlist reached incase of pagination
onEndReachedThresholdnumbernumberrepresents the number of screen lengths you should be from the bottom before it fires the event

Components

ComponentsDescription
ListEmptyComponentListEmptyComponent
isRequestingComponentListFooterComponent

Styles

PropDefaultTypeDescription
textInputStyle{ borderRadius: 10, borderWidth: 1, width: width * 0.8, height: height * 0.05, padding: 10}styletextInputStyle
modalStyle{ borderRadius: 10, width: width * 0.8, height: height * 0.3, backgroundColor: 'white', alignSelf: 'center'}stylemodalStyle
contentContainerStyle{}stylecontentContainerStyle for flatlist
flatListStyle{}stylestyle for flatlist
placeholderTextColorhexadecimalplaceholderTextColor
listItemStyle{padding: 10}stylestyle for each item in flatlist
listItemTextStyle{fontSize: 16}stylelistItemTextStyle
backDropOpacity0.65numberbackDropOpacity of modal

Multi Picker ( Can use same Props, Components and Styles of Single Picker in addition to: )

Props

PropDefaultTypeDescription
saveButtonTitleSavestringtitle of save button

Styles

PropDefaultTypeDescription
saveButtonStyle{borderRadius: 30, minHeight: height * 0.04, width: width * 0.3, backgroundColor: 'black', justifyContent: "center", alignItems: 'center', alignSelf: "center", marginTop: 20, marginHorizontal: width * 0.015}stylesaveButtonStyle
saveButtonTitleStyle{color: "white", fontSize: width * 0.04}stylesaveButtonTitleStyle
selectedItemIconStyle{height: 15, width: 15, alignSelf: 'center'}styleselectedItemIconStyle

Components

ComponentsDescription
selectedItemIconComponentselectedItemIconComponent

Author

šŸ‘¤ Ahmed Halbas

šŸ¤ Contributing

Contributions, issues and feature requests are welcome!Feel free to check issues page.

Show your support

Give a ā­ļø if this project helped you!

2.0.2

1 year ago

2.0.1

2 years ago

2.0.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago