Add the version of the litho packages you use. You can paste the dependency
section of the gradle file if you have one.
Litho version: 0.8.0
Sections version: 0.8.0
I am using the new Sections API to display a list of items. I have pull to refresh enabled. When pulled, a service gets called to fetch data. After that i update the state. But the ptr spinner is still visible.
I call the service to fetch data when spinner is pulled:
@OnCreateService
static DataLoader onCreateService(SectionContext c, @State List connectionData) {
return new DataLoader();
}
@OnRefresh
static void onRefresh(SectionContext c, DataLoader service) {
service.refetch();
}
@OnBindService
static void onBindService(final SectionContext c, final DataLoader service) {
service.registerLoaderEvent(ListSection.dataLoaded(c));
}
@OnUnbindService
static void onUnbindService(final SectionContext c, final DataLoader service) {
service.unregisterLoaderEvent();
}
@OnEvent(MyData.class)
static void dataLoaded(final SectionContext c, @FromEvent List data) {
ListSection.updateData(c, data);
}
@OnUpdateState
static void updateData(final StateValue<List> connectionData, @Param List data) {
connectionData.set(data);
}
Thanks for raising the question @sjthn you should dispatch a loading event with a SUCCEEDED loading state to instruct the RecyclerCollectionComponent you have completed data fetching. (See https://fblitho.com/docs/communicating-with-the-ui#oneventloadingeventclass)
We should definitely link this part in the services documentation thanks for bringing it to our attention! If you have any additional problems please let us know!
Thanks @dsyang for quick response. That works!
I changed my dataLoaded event listener:
@OnEvent(MyData.class)
static void onDataLoaded(final SectionContext c, @FromEvent List data) {
ListSection.updateData(c, data);
SectionLifecycle.dispatchLoadingEvent(c, false, LoadingState.SUCCEEDED, null);
}
Would be really helpful if linked in docs.
Most helpful comment
Thanks @dsyang for quick response. That works!
I changed my dataLoaded event listener:
@OnEvent(MyData.class) static void onDataLoaded(final SectionContext c, @FromEvent List data) { ListSection.updateData(c, data); SectionLifecycle.dispatchLoadingEvent(c, false, LoadingState.SUCCEEDED, null); }Would be really helpful if linked in docs.