Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added handlers for prev/next + customizable view for selected days #146

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

SolutiLyon
Copy link

@SolutiLyon SolutiLyon commented Jun 5, 2017

Usage example :

const prevHandler = (mom) => {
    // Disable prev if previous month < today
    const prevEnabled = mom.diff(moment(), 'months', true) >= 0;

    this.setState({
        prevEnabled,
        currentMonth: prevEnabled ? mom : moment()
    });
    return prevEnabled;
};

const nextHandler = (mom) => {
    // Always enable next
    const prevEnabled = true;

    this.setState({
        prevEnabled,
        currentMonth: mom
    });
    return true;
};

const getDayView = (date, isWeekend, isSelected, isToday, event, caption) => {
    console.log("DIFF", date.diff(moment(), "days"));

    // Custom view for selected day
    if (isSelected) {
        return (
            <View style={styles.daySelected}>
                <View style={styles.daySelectedContent}>
                    <Text style={styles.daySelectedText}>{caption}</Text>
                </View>
            </View>
        );
    }

    // Opacity to 0.5 for days before today
    return (
        <Text style={{...styles.dayText, opacity: date.diff(moment(), "days") < 0 ? 0.5 : 1}}>{caption}</Text>
    );
};

<Calendar  ...
    viewForDay={getDayView}
    onTouchPrev={prevHandler}
    onTouchNext={nextHandler}
/>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant