react-native-calendars icon indicating copy to clipboard operation
react-native-calendars copied to clipboard

Making Calendar view default with Agenda

Open fithaN opened this issue 7 years ago • 24 comments

Description

Is there a way to show the calendar view with selectable dat and arrows in the screen as default? And open the agenda view when a date is clicked?

fithaN avatar Jan 17 '18 01:01 fithaN

Hi, could you define your requirements in more detail?

tautvilas avatar Feb 01 '18 12:02 tautvilas

Hi, sure. Some people doesn't know how to close the Agenda. Can you implement feature for control initial state of the closed Agenda?

Dmytro96 avatar Feb 06 '18 22:02 Dmytro96

+1 for this feature. Based from user experience feedback, some users may will want to select a date first in the calendar view rather than being a locked first on the default week.

nikojohnarellano avatar Mar 19 '18 00:03 nikojohnarellano

@tautvilas Yes. So basically the view will show the calendar with the selectable dates /dates with dots in it. Once we click on one of the dates the agenda view appears. I think its kind of a way to better make it user friendly and easy to use as Dmytro96 suggested.

fithaN avatar Mar 19 '18 02:03 fithaN

During beta testing most of my user's didn't realize that the "knob" was a clickable button.

I changed the knob to an icon but would prefer if the Agenda would start as a calendar list. This would train the user immediately that they can switch between calendar views.

odesey avatar Mar 21 '18 00:03 odesey

@odesey @nikoootine

Hey, @Dmytro96 actually implemented that in this fork: https://github.com/ygalustov/react-native-calendars.

A new prop added: isDefaultViewCalendar

The only thing is that the fork is not synced with the upstream yet. I might need to do that and push changes back to upstream.

ygalustov avatar Mar 21 '18 21:03 ygalustov

Hi @ygalustov, what day will sync with the upstream? I'm having the same problem and would like to use the new functionality.

fernandoantunes avatar Mar 26 '18 19:03 fernandoantunes

Hi @tautvilas, what day will sync with the npm?

fernandoantunes avatar Apr 02 '18 20:04 fernandoantunes

this has not been proposed as PR so not going to master branch yet @fernandoantunes

tautvilas avatar Apr 03 '18 11:04 tautvilas

@fernandoantunes Sorry guys, was extremely busy these days, will try to smash it soon

ygalustov avatar Apr 03 '18 21:04 ygalustov

Very good, we'll be waiting, Thanks @ygalustov

fernandoantunes avatar Apr 04 '18 18:04 fernandoantunes

Thank you @ygalustov , this is going to be a great adding!

julienkessels avatar Apr 13 '18 10:04 julienkessels

Not so good solution for switch to calendar view programmatically

this.agenda.setScrollPadPosition(0, true);
this.agenda.enableCalendarScrolling();

Because I am using other buttons than the knob to trigger it, so I have to run the knob code manually.

cylim avatar Apr 26 '18 15:04 cylim

@cylim in which snippet of code did you put it?

fernandoantunes avatar May 14 '18 21:05 fernandoantunes

is this feature on master yet?

hszeto avatar May 29 '18 18:05 hszeto

I used the following to toggle the calendar via a button in the navigation bar.

You can toggle it via the static method YourComponentName.toggleCalendar()

  1. Store the component in a ref
  2. Create the "toggleCalendar" method
  3. Toggle it where ever you want via the static method.
/**
 * A ref to store our agenda component in
 */
let agendaRef = React.createRef();

/**
 * Toggle the calendar programatically
 */
static toggleCalendar() {
    if (agendaRef.state.calendarScrollable) {
        agendaRef.setScrollPadPosition(agendaRef.initialScrollPadPosition(), true);
        agendaRef.setState({ calendarScrollable: false })
        agendaRef.calendar.scrollToDay(agendaRef.state.selectedDay.clone(), agendaRef.calendarOffset(), true);
    } else {
        agendaRef.setScrollPadPosition(0, true);
        agendaRef.enableCalendarScrolling();
    }
}

/**
 * Store the agenda component in a ref so we can toggle it programatically.
 */
render() {
    <AgendaView ref={(ref) => agendaRef = ref}
        {...otherProps}
    />
}

Hope this helps someone. 👍

lakhman avatar Jun 19 '18 14:06 lakhman

So this is how I solved the calendar closing problem:

<Agenda .... ref={ref => (agendaRef = ref)} onCalendarToggled={calendarOpened => this.setState({ calendarOpened })} onDayPress={day => { this.state.calendarOpened && agendaRef.setScrollPadPosition(0, true); }} />

DavitVosk avatar Jun 29 '18 18:06 DavitVosk

Is this already merge in master?

webdevsyd avatar Jul 21 '18 05:07 webdevsyd

@webdevsyd if your calendar does not work as in the example of this package, then maybe it is UI problem. I was facing such kind of problems.

DavitVosk avatar Jul 30 '18 13:07 DavitVosk

Is there any news about the fork ? Creating a PR or something ?

GuillaumeRZ avatar Jan 24 '19 12:01 GuillaumeRZ

Is there any news on this feature to have a default view as calendar instead of selected day. Can someone help please ?

olivier545 avatar Jun 18 '19 16:06 olivier545

OK, I figured it out based on @cylim answer In module/src/agenda/index.js

onScrollPadLayout() { replaced this.setScrollPadPosition(this.initialScrollPadPosition(), false); by this.setScrollPadPosition(0, true); this.enableCalendarScrolling();

olivier545 avatar Jun 18 '19 17:06 olivier545

I'm in 2022 and it would be great for me to have this feature. Because i needing now.

Apozzi avatar Apr 15 '22 00:04 Apozzi

this.setScrollPadPosition(0, true); this.enableCalendarScrolling();

love. u

fukemy avatar Jul 13 '22 07:07 fukemy

Credit to @lakhman I modified his solution to work with this current version of react-native-calendars": "^1.1275.0 Here is how i did it programmatically


let agendaRef = useRef(null)

  useEffect(() => {
        toggleCalendarAgenda()
      return () => {}
    }, [])
    

    const toggleCalendarAgenda = () =>{
       //wait for the component to mount
        setTimeout(() => {
            if (agendaRef.state.calendarScrollable) {
                agendaRef.setScrollPadPosition(agendaRef.initialScrollPadPosition(), true);
                agendaRef.setState({ calendarScrollable: false })
                agendaRef.calendar?.current?.scrollToDay(agendaRef.state.selectedDay.clone(), agendaRef.calendarOffset(), true);
            } else {
                agendaRef.setScrollPadPosition(0, true);
                agendaRef.enableCalendarScrolling();
            }
        }, 50);
        
    }
  return (<Agenda
        ref={(ref) => agendaRef = ref}       
        // Max amount of months allowed to scroll to the past. Default = 50
        pastScrollRange={50}
        // Max amount of months allowed to scroll to the future. Default = 50
        futureScrollRange={50}
        // Hide knob button. Default = false
        hideKnob={false}
        //other props
    />)

torver213 avatar Jan 28 '23 08:01 torver213

I have the same version but even with your advice I still have the same problem on iOS. Please provide a solution

pawlone avatar Apr 05 '23 13:04 pawlone

+1

samiiku avatar Sep 09 '23 18:09 samiiku