Giter Club home page Giter Club logo

react-native-wheel-picker-android's Introduction

Note: this is a heavily modified fork, the original can be found here

@delightfulstudio/react-native-wheel-picker-android

npm version npm version

Android-only WheelPicker (based on https://github.com/AigeStudio/WheelPicker) and DatePicker components that mimic their standard iOS counterparts (PickerIOS and DatePickerIOS, correspondingly).

DatePicker interface is mostly compatible with DatePickerIOS.

Installation

yarn add @delightfulstudio/react-native-wheel-picker-android

Auto linking

Note: Doesn't work with RN v0.55, not tested with v0.56

react-native link @delightfulstudio/react-native-wheel-picker-android

Manual linking

Open android/settings.gradle and add the following two lines right above include ':app':

include ':react-native-wheel-picker-android'
project(':react-native-wheel-picker-android').projectDir = new File(rootProject.projectDir, '../node_modules/@delightfulstudio/react-native-wheel-picker-android/android')

Open android/app/build.gradle and add the following line to dependencies section:

compile project(':react-native-wheel-picker-android')

Open android/app/java/com/{your package name}/MainApplication.java and add the following line right below package com.{your package name}

import com.delightfulstudio.wheelpicker.WheelPickerPackage;

In the same file find method getPackages() and add new WheelPickerPackage() at the end of the returned array, like this:

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          new WheelPickerPackage() // << add this line
      );
    }

Usage

import { WheelPicker, DatePicker } from '@delightfulstudio/react-native-wheel-picker-android'
import React, { Component } from 'react';
import {
    StyleSheet,
    View
} from 'react-native';

const wheelPickerData = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday','Saturday'];
const now = new Date()

const styles = StyleSheet.create({
    container: {
        flex: 1,
        alignItems: 'center',
    },
    wheelPicker: {
        width: 200,
        height: 150
    }
});

export default class MyPickers extends Component {
    render() {
        return (
            <View style={ styles.container }>
                <WheelPicker
                    onItemSelected={ this.onItemSelected }
                    isCurved
                    data={ wheelPickerData }
                    visibleItemCount={5}
                    style={ styles.wheelPicker }/>
                <DatePicker
                    date={ now }
                    mode="datetime"
                    onDateChange={ this.onDateSelected }/>
                <DatePicker
                    date={ now }
                    mode="time"
                    onDateChange={ this.onTimeSelected }/>
            </View>
        );
    }

    onItemSelected = event => {
        // do something
    };

    onDateSelected = date => {
        // do something
    };

    onTimeSelected = date =>{
        // do something
    };
}

To check out working example:

  1. Clone this repo
  2. Install root packages: yarn or npm install
  3. Install example packages: in the example folder, do yarn or npm install
  4. Start metro server: in the example folder, do yarn start or npm start
  5. Compile/start Android app: in the example folder, do yarn run-android or npm run-android

Wheel Picker

import { WheelPicker } from '@delightfulstudio/react-native-wheel-picker-android'
...

    render() {
        const arr = [1,2,3];
        return (
        <WheelPicker
            onItemSelected={ event => {/* do something */} }
            isCurved
            isCyclic
            data={arr}
            style={{width:300, height: 300}}/>
        );
  }
...

Props

Prop Default Type Description
onItemSelected null func Callback when user select item {data: 'itemData', position: 'itemPosition'}
data default string array array Data array (string or number type)
isCurved false bool Make Wheel Picker curved
isCyclic false bool Make Wheel Picker cyclic
isAtmospheric false bool Design Wheel Picker's items
selectedItemTextColor grey string Wheel Picker's selected Item Text Color
itemSpace 20 number Wheel Picker's items spacing
visibleItemCount 7 number Wheel Picker's items max visible count
renderIndicator false bool Show Wheel Picker indicator
indicatorColor transparent string Indicator color
indicatorSize 5 number Indicator stroke size
isCurtain false bool Wheel Picker curtain
curtainColor transparent string Wheel Picker curtain color
itemTextColor grey string Wheel Picker's items color
itemTextSize 20 number Wheel Picker's items text size
itemTextFontFamily null string Wheel Picker's items text font name
itemTextAlign 'center' enum('left', 'center', 'right') Wheel Picker's items text alignment
selectedItemPosition null number Select current item position
backgroundColor transparent string Wheel Picker background color
allowFontScaling false bool Font scaling based on Pixel Ratio

data

An array of options. This should be provided with an array of strings or array of numbers.

onItemSelected(event)

Callback with event in the form event = { data: 1, position: 0 }

Date Picker

import { DatePicker } from '@delightfulstudio/react-native-wheel-picker-android'
...

    render() {
        const now = new Date();
        return (
            <DatePicker
                date={ now }
                mode="datetime"
                onDateChange={ this.onDateSelected }/>
        );
    }

    onDateSelected = date => {
        // do something
    };
...

Props

Prop Required Default Type DatePickerIOS Description
date [ ] now Date [x] The currently selected date
onDateChange [x] null func [x] Date change handler
minimumDate [ ] maximumDate - 1 year or date Date [x] Minimum date - restricts the range of possible date/time values
maximumDate [ ] minimumDate + 1 year Date [x] Maximum date - restricts the range of possible date/time values
minuteInterval [ ] 1 enum(1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30) [x] The interval at which minutes can be selected
mode* [ ] 'date' enum('date', 'time', 'datetime') [x] The date picker mode
locale** [ ] Locale ID [x] The locale for the date picker
style*** [ ] null obj [x] The control container style
styles**** [ ] { picker, date, hours, minutes, gap, AM } [ ] The control part styles - allows to adjust control internal layout, each property is an object with style properties, ex: { picker: { height: 100 } }
todayTitle [ ] 'Today' string [ ] The title for today date item

* mode: 'date' doesn't support year selection, therefor it is not suitable for large range of dates, ex: birthdays.

** locale: "<locale id>" support is limited to 12/24 mode and names of months and days, it also requires explicit import 'moment/locale/<locale id>' somewhere in your script for any non-english locales to work properly.

*** style can be used to change background color and surrounding margin/padding

**** styles were tested only with size, padding and margin style properties, other properties may not work

Questions or suggestions?

Feel free to open an issue

react-native-wheel-picker-android's People

Contributors

a-golovanov avatar agenthunt avatar agurtovoy avatar andrewtsar0w avatar artemkosiakevych avatar maxtoyberman avatar naoty avatar nimatrueway avatar shhzdmrz avatar snnikitin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-native-wheel-picker-android's Issues

Startup error

  • What went wrong:
    Could not determine the dependencies of task ':delightfulstudio_react-native-wheel-picker-android:compileDebugAidl'.

Could not resolve all task dependencies for configuration ':delightfulstudio_react-native-wheel-picker-android:debugCompileClasspath'.
Could not resolve cn.aigestudio.wheelpicker:WheelPicker:1.1.2.
Required by:
project :delightfulstudio_react-native-wheel-picker-android
> Could not resolve cn.aigestudio.wheelpicker:WheelPicker:1.1.2.
> Could not get resource 'https://www.jitpack.io/cn/aigestudio/wheelpicker/WheelPicker/1.1.2/WheelPicker-1.1.2.pom'.
> Could not GET 'https://www.jitpack.io/cn/aigestudio/wheelpicker/WheelPicker/1.1.2/WheelPicker-1.1.2.pom'. Received status code 401 from server: Unauthorized

debug assets

info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 1009 file(s) to forward-jetify. Using 8 workers...
info Starting JS server...
info Installing the app...

Task :react-native-wheel-picker-android:packageDebugAssets FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings
93 actionable tasks: 32 executed, 61 up-to-date

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':react-native-wheel-picker-android:packageDebugAssets'.

Failed to create directory 'D:\fithub_personal_assistant\reelclient\node_modules\react-native-wheel-picker-android\android\build\intermediates\incremental\packageDebugAssets'

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 2m 15s

typescript

Are you planning to add typescript support?

[feature request] IndicatorHeight property

indicator default height on android is half of ios and there is no way to change the gap between indicator lines to make app on both os look same

how it look on ios:
image

how it look on android:
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.