Skip to content

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