Giter Site home page Giter Site logo

gusparis / react-native-month-year-picker Goto Github PK

View Code? Open in Web Editor NEW
105.0 2.0 72.0 1.79 MB

React Native Month Picker component for iOS & Android

License: MIT License

Java 48.02% Objective-C 29.98% Ruby 3.77% JavaScript 14.68% Starlark 3.56%
month-picker month-year-picker react-native react android ios java objective-c

react-native-month-year-picker's People

Contributors

asaaonline avatar dependabot[bot] avatar eminsr avatar gusparis avatar jeffreynerona avatar mesutaltuncu avatar revit94 avatar semantic-release-bot avatar

Stargazers

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

Watchers

 avatar  avatar

react-native-month-year-picker's Issues

Customizable buttons

Hi @gusparis,
first of all, thanks for developing this component, it's working great for me.
I was wondering if there's a way to customize the button section. Apart from "Cancel" and "Done", I'd like to add an extra button to perform a custom action (in my case, to trigger a date deletion in the component calling the picker), and I'd like to include it in the button section. Do you think it's feasible, perhaps by giving us a way to inject the whole button section component as an array of buttons or a customized component?
Thanks

Model opens up atuomatically when app come from background state to foreground state

i have just copied your example code and it works fine when app is in foreground but when we put the app in background and open it up again that time the picker opens up automatically.please refer to the video attacked bellow.
versions

"react": "16.13.1",
"react-native": "^0.63.1",
"react-native-month-year-picker": "^1.3.2",

my code

`
/**

import Navigator from "@navigation/Router";
import rootReducer from "@redux/RootReducer";
import { ThemeContextProvider } from "@theme/ThemeHelper";
// import React from "react";
import Apps from "./src/App";
import { name as appName } from "./app.json";
import { AppRegistry } from "react-native";

// const App = () => (
//
//
//
// );

AppRegistry.registerComponent(appName, () => App);

import React, { useState, useCallback } from "react";
import { SafeAreaView, StyleSheet, Text, TouchableOpacity } from "react-native";
import moment from "moment";

import MonthPicker from "react-native-month-year-picker";

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#dfe6e9"
},
button: {
justifyContent: "center",
alignItems: "center",
backgroundColor: "#b2bec3",
borderRadius: 4,
padding: 10
},
buttonText: {
color: "#2d3436"
}
});

const DEFAULT_FORMAT = "MM-YYYY";
const DEFAULT_OUTPUT_FORMAT = "MMM-YYYY";

const App = () => {
const [date, setDate] = useState(new Date());
const [show, setShow] = useState(false);

const showPicker = useCallback((value) => setShow(value), []);

const onValueChange = useCallback(
(event, newDate) => {
const selectedDate = newDate || date;

  showPicker(false);
  setDate(selectedDate);
},
[date, showPicker]

);

return (

Month Year Picker Example
{moment(date, DEFAULT_FORMAT).format(DEFAULT_OUTPUT_FORMAT)}
<TouchableOpacity onPress={() => showPicker(true)} style={styles.button}>
OPEN

{show && (
<MonthPicker
onChange={onValueChange}
value={date}
minimumDate={new Date()}
maximumDate={new Date(2025, 5)}
enableAutoDarkMode={false}
/>
)}

);
};

`

ezgif com-video-to-gif

Empty modal

image

Version used: 1.8.0

{isShowMonthPicker && (
          <MonthPicker
            onChange={(event, newDate) => {
              switch (event) {
                case ACTION_DATE_SET:
                  changeMonth(moment(newDate));
                  break;
                case ACTION_NEUTRAL:
                  break;
                case ACTION_DISMISSED:
                default:
              }
              setIsShowMonthPicker(false);
            }}
            value={monthlyState.monthAndYear.toDate()}
            minimumDate={new Date()}
            maximumDate={new Date(2025, 5)}
          />
        )}

App crashes while opening react native month year picker

App is crashing when opening picker
Using:
"react-native": "0.62.2"
"react-native-month-year-picker": "^1.3.2",

Code:
import React, { useState, useCallback } from 'react';
import { View, SafeAreaView, Text,TouchableOpacity } from 'react-native';
import MonthPicker from 'react-native-month-year-picker';

const App = () => {
const [date, setDate] = useState(new Date());
const [show, setShow] = useState(false);

const showPicker = useCallback((value) => setShow(value), []);

const onValueChange = useCallback(
(event, newDate) => {
const selectedDate = newDate || date;

  showPicker(false);
  setDate(selectedDate);
},
[date, showPicker],

);

return (

Month Year Picker Example
{/* {moment(date, "MM-YYYY")} */}
<TouchableOpacity onPress={() => showPicker(true)}>
OPEN

{show && (
<MonthPicker
onChange={onValueChange}
value={date}
minimumDate={new Date()}
maximumDate={new Date(2025, 5)}
enableAutoDarkMode={false}
/>
)}

);
};

export default App;

Tried following steps but not working
react-native run-android
npm start --reset-cache

Neutral button stops firing (iOS)

Hello again Gustavo,
I've been noticing an odd behavior on iOS with the neutral button you added in #48. Sometimes, after I've been using my app for a while, the button just stops firing the NEUTRAL_ACTION event. Unfortunately I don't have a code snippet to show you to replicate the problem, but it happens quite regularly and I'm still trying to figure out why. I'll keep you posted on the matter.
Cheers.

okButton & cancelButton not working (iOS)

okButton & cancelButton props work on Android but don't work in iOS (default values are shown):

Simulator: iPhone 11 (iOS 13.2.2), iPhone 11 (iOS 14)
react native: 0.63.2
react-native-month-year-picker: 1.6.0

Has any event to listen when modal is going to close?

Is there an event that is fired when modal was closed?
Clicking on the button Ok, or Cancel from the onChange function it's ok and changes the value. But when you click outside of the modal, and the modal was closed without clicking on button Cancel our Ok, i am no longer able to open the modal and select a new date. Help

Issue after installing mac os big sur - Execution failed for task ':react-native-month-year-picker:compileDebugJavaWithJavac'.

Task :react-native-month-year-picker:compileDebugJavaWithJavac FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.1.1/userguide/command_line_interface.html#sec:command_line_warnings
348 actionable tasks: 2 executed, 1 from cache, 345 up-to-date

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':react-native-month-year-picker:compileDebugJavaWithJavac'.

Could not find tools.jar. Please check that /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home contains a valid JDK installation.

  • 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 17s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDevDebug -PreactNativeDevServerPort=8081

Couldn't install it using yarn

mohamadmek@Mohamads-MacBook-Pro centreminefrontend % yarn add @react-native-month-year-picker
yarn add v1.22.5
[1/4] 🔍 Resolving packages...
error An unexpected error occurred: "https://registry.yarnpkg.com/@react-native-month-year-picker: Request "https://registry.yarnpkg.com/@react-native-month-year-picker\" returned a 405".
info If you think this is a bug, please open a bug report with the information provided in "/Users/mohamadmek/Documents/CentremineProject/centreminefrontend/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
mohamadmek@Mohamads-MacBook-Pro centreminefrontend %

Incorrect work on android

when I clicked Ok at dialog, then picker opens multiple times and doesn't close, i can do it only by clicking on Ok button
and I can't see action for Cancel button, and can't setVisible for modal like "false" value and modal always visible.
please help

Android: Method addObserver must be called on the main thread

image

Component code:

`import React, {memo, useCallback, useMemo, useRef, useState} from 'react';
import format from 'date-fns/format';
import MonthPicker, {ACTION_DATE_SET} from 'react-native-month-year-picker';
import {Platform} from 'react-native';

import {Container, Modal, PaymentTextField} from './styles';

function emptyFun() {}

// Interface
interface IDatePickerFieldProps {
input: {value: string; onChange: () => void};
meta: any;
}

const DatePickerField = memo(
({input, meta, ...props}) => {
const textFieldRef = useRef(true);

const [pickerOpen, setPickerOpen] = useState(false);

const handleClosePicker = useCallback(() => {
  setPickerOpen(false);
}, []);
const handleOpenPicker = useCallback(() => {
  setPickerOpen(true);
}, []);

const onValueChange = useCallback(
  (event, newDate) => {
    switch (event) {
      case ACTION_DATE_SET:
        input.onChange(newDate);
        break;

      default:
        handleClosePicker();
    }
    handleClosePicker();
  },
  [input, handleClosePicker],
);

const inputForTextField = useMemo(
  () => ({
    ...input,
    onFocus: () => {
      handleOpenPicker();
      textFieldRef.current?.blur();
    },
    value: input.value ? format(input.value, 'MM/yy') : '',
    onChange: emptyFun,
  }),
  [textFieldRef, input, handleOpenPicker],
);

const currentDate = useMemo(() => new Date(), []);

return (
  <>
    <PaymentTextField
      input={inputForTextField}
      meta={meta}
      forwardRef={textFieldRef}
      {...props}
    />
    {Platform.OS === 'android' ? (
      pickerOpen && (
        <MonthPicker
          onChange={onValueChange}
          value={input.value || currentDate}
          minimumDate={new Date()}
          locale="en"
        />
      )
    ) : (
      <Modal
        isVisible={pickerOpen}
        onBackButtonPress={handleClosePicker}
        onBackdropPress={handleClosePicker}
        backdropOpacity={0}
        backdropTransitionOutTiming={0}
        animationInTiming={300}
        animationOutTiming={300}
        coverScreen
        animationOut="slideOutDown"
        isSwipeable={false}
        {...props}>
        <Container>
          <MonthPicker
            onChange={onValueChange}
            value={input.value || currentDate}
            minimumDate={currentDate}
            locale="en"
            mode="number"
          />
        </Container>


      </Modal>
    )}
  </>
);

},
);

export {DatePickerField};
`

Scroll multiple Items at once not possible (Android)

When trying to scroll multiple months or years at once, the animation is shown but jumps back to the previous selected item. From a user perspective it feels weird to be resetted after scrolling a few months at once.

In my case only tapping item by item through the list makes it possible to select something.

Also as a sidenote: It would be awesome to be able to jump from December 2020 to January 2021 with one click.

Hit me up, if you need further information

on IOS, it's always dark mode

on IOS,
even though i set enableAutoDarkMode as false, the color of picker is still dark mode style.

how can i fix this?

Expo

Cannot read property 'open' of undefined for MonthPicker.

iOS: Not showing Done and Cancel Button on first render, scroll the spin crash the app

React Native version :0.63.3

  • when first enter the page and trigger the month-year-picker, Not showing Done and Cancel Button. at this time scroll the spin would some times make the app crash.
  • navigate to other page and navigate back, re-trigger the month-year-picker, it works fine.

as it would crash the app, I guess is there some code issue in this situation?

attached the screen and video. thanks

RPReplay_Final1628132543.MP4

image

this is my code:

render() {
    const { value, minimumDate, maximumDate, locale } = this.state;
    return (
      <MonthPicker
        onChange={this.onValueChange}
        value={value}
        minimumDate={minimumDate}
        maximumDate={maximumDate}
        mode="full"
        autoTheme={false}
        locale={locale}
      />
    );
  }

localization

Hello, can you please tell me how to make localization for this picker, or is this function not yet implemented? If not, is it planned to be implemented in the near future?

Possibility to provide month names

Translated months to polish are not grammatically correct if there is no day column before (like it's in original picker). It would be cool to provide prop with mappings or something

Error in release mode iOS

I got error on release iOS application

when I select month and year on release I can get any year that I selected but I still got January month when submit.
It's work on simulator and debug mode on device.

"RNMonthPicker" was not found in the UIManager using Expo

Hey,

First of all thanks for creating this datepicker.

I am using the following packages:
Expo: "expo": "^39.0.3"
"react-native": "^0.63.2"

I have installed the package using:
npm install react-native-month-year-picker --save

As per my knowledge there is no linking/autolinking in a managed expo project so the quesiton is how can i make it work?

When i tap on the button to show the datepicker i get the following error:
"RNMonthPicker" was not found in the UIManager

Many thanks,
Trix

Focus on scroll

It would be nice to have a way to focus on scroll Months.

[Android] I can still select dates beyond minimumDate and maximumDate

Hi again Gustavo,
I have yet another report: on Android, I set the maximum date to December 2020 with the prop maximumDate={new Date()}, but if I carefully and slowly drag the year column I can still select the next year (2021 in this case). I can't go any further that that luckily. The same goes with minimumDate={new Date()}, I can still select 2019.
Same story with months column on both directions.

Some specs: library v. 1.6.2 (latest), Android v. 10, confirmed on several devices (Huawei, Xiaomi, Nokia).

Can you look into that? Thanks.
In the meantime, Feliz Navidad man.

[Request] Please provide index.d.ts for typescript

Dear contributors.

I found this repo yesterday and am thinking this is exactly what I want.

However, since I am using the Typescript and cannot use the component without suppressing type error.
To use your component, I would like you to provide the typedef as a part of the code provided.

If you do not mind me contributing, I can make PR by myself in this weekend or next week.

Best Regard

Reference:
Typescript Official Document: Modules .d.ts

[IOS] Picker width does not update after orientation change

MonthPicker.ios.js

const { width } = Dimensions.get('screen');

const styles = StyleSheet.create({
  container: {
    width,
    position: 'absolute',
    zIndex: 500,
    bottom: 0,
  },
  pickerContainer: {
    height: 244,
    width,
  },
  picker: { flex: 1 },
});

When the orientation updated to landscape, the width remains unchanged.
The picker width is less than the screen width.

Months not looping

Months are not looping on scroll. If the wheel is focused on January, and I scroll up, It should go to December-November...

selectedDate not working

using hooks, if you click another month and year, always returns to the current month and year. RN 0.63.4

Not supporting to all versions in android

@gusparis this module is not working in some versions in the android 5 & 11, in android version 9 it is working,

i didn't checked in remaining versions also, only i tested in above mentioned versions. it was working only in android 9

not working in android 11 & 5

can you help me to fix this issue.
Thanks

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.