react-native-calendars: CalendarList rendering super slow
I am facing performance issues with the CalendarList.
- Tested on Samsung Galaxy S9 and OnePlus 3
- I am using 12 months in total to display
- I am using expo, the build-version is a little bit faster but still very slow.
- Using version 1.1255.0 (latest one) of react-native-calendars
const [show, setShow] = useState<boolean>(false)
<SafeAreaView style={styles.container}>
<View style={{flex: 1}}>
<Button title={"Toggle calendar"} onPress={() => setShow((s) => !s)}/>
</View>
<View style={{flex: 9}}>
{show &&
<CalendarList
// style={{width: deviceWidth}}
onDayPress={handleDayPress}
markedDates={{
[selectedDate]: {selected: true}
}}
theme={{
selectedDayBackgroundColor: colors.primary,
todayTextColor: colors.primary
}}
pastScrollRange={12}
futureScrollRange={0}
scrollEnabled={true}
showScrollIndicator={true}
/>
}
</View>
</SafeAreaView>
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 11
- Comments: 27
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I’m having terrible performance issue with ExpandableCalendar. Particularly when selecting different date or month. Has anyone found a solution to this?
This is issue is not in any way stale and it’s a major pitfall when using this library.
There is also a major problem using the Agenda component since it cannot be rendered consistently without the actual layout. If you try pre rendering the agenda in a non lazy tab navigator the Agenda week will be out of place. This means that I cannot load the Agenda page on app load but only when the user switches to that particular tab, resulting in the waiting time discussed above. It seems to me that no workaround is really feasible in this situation, any ideas are more than welcome.
I am using it with CalendarList, extremely slow on both ios and android
Still having performance issue with ExpandableCalendar in android. Any news about this?
I found a solution. Oddly enough it was the
themeproperty that slowed down the component for me. I defined the theme in aStyleSheet.createand everything works!For more optimization, you should not put the
keypropertyExample code:
I’m facing the same issue.
I was having performance issues as well and decided to use react-native-calendario because of the way its implemented and I only needed the CalendarList with no performance hit
@callaars How can a component like this be so slow? Thanks for your hint but in my oppinion this is a very critical issue for a basic calender like this (I know it also supports way more complex features). A component containing arround 40 text views just cannot be that slow. This seems like major performance issues or any bug
Same here, onDayPress takes a crazy amount of time to load
We have the same issues with the onDayPress, very laggy on iOS. with “only” 12 months displayed.
Same with me, but as i removed the Theme, it stopped lagging.
Same issue here. It works fine on iOS but rendering the calendar on Android is really really slow
Hi, i would like to share my approach here… To anticipate load time issues, I initialized my screen with some lighter component like ActivityIndicator and as soon as the screen get rendered, I replace ActivityIndicator with CalendarList. To achieve this you can use a combination of useState() with true as init value, then set state to false inside useEffect().
@callaars I tried you solution without success. The issue for me is only on Android, iOS is fine. I even tried to have the Calendar without any
markedDatesvery basic and it still takes 2-3s to open. On iOS it’s instant.I think you are misunderstanding a core concept here. On React Native all the date calculations and layouting (in this package) are done on the JS thread. The JS thread is single threaded, it can only handle so many permutations before it starts lagging. This is the core frustration for a lot of React Native developers.
Not that it would affect performance too much, I think you also misunderestimate how many components are being rendered by the calendar. If you look at this little loom I made you can see that it at least renders one month before and one month after: https://www.loom.com/share/12ad056dd0a7407589cf49cb913ba411
As I said though, rendering is never the issue as that’s on the Native side and that’s fast enough. It’s the permutations on the JS side that are the problem.
To overcome this problem you have to be smarter how you develop and don’t just assume all components will have a blazing performance, because simply said that’s just not the case.
My main tip still stands and I will reiterate it a little. Basically what you want to do is render the component even if it isn’t activated yet. In this loom you can see that I can open the calendar smoothly in one go, that’s because I render it in a
height: 0view inside aSuspensecomponent. That way it is loaded as soon as the application is done loading, and therefor immediately showable.In your case, and correct me if I’m wrong, you’re rendering the component once you click on the button, and not earlier. That will never give you the performance you require.
See demo: https://www.loom.com/share/2e308976ea5245b386175bd6d8521249