From e08c6a21fe45f83d7cba551ea5b5b0ddb7654836 Mon Sep 17 00:00:00 2001 From: Laimonas Turauskas Date: Tue, 3 Dec 2024 10:24:12 -0500 Subject: [PATCH] [Android] Add onPreRenderFragmentState callback. --- .../main/java/com/instacart/formula/android/ActivityStore.kt | 4 +++- .../com/instacart/formula/android/internal/ActivityManager.kt | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/formula-android/src/main/java/com/instacart/formula/android/ActivityStore.kt b/formula-android/src/main/java/com/instacart/formula/android/ActivityStore.kt index 0452147d..a565d255 100644 --- a/formula-android/src/main/java/com/instacart/formula/android/ActivityStore.kt +++ b/formula-android/src/main/java/com/instacart/formula/android/ActivityStore.kt @@ -14,13 +14,15 @@ import io.reactivex.rxjava3.disposables.Disposable * configuration changes. Check [com.instacart.formula.android.StreamConfigurator] for utility methods. * @param configureActivity This is invoked as part of [com.instacart.formula.FormulaAndroid.onPreCreate]. You can * use this callback to inject the activity. - * @param onRenderFragmentState This is invoked after [FragmentState] has been updated. + * @param onPreRenderFragmentState This is invoked before [FragmentState] is applied. + * @param onRenderFragmentState This is invoked after [FragmentState] has been applied. * @param onFragmentLifecycleEvent This is callback for when a fragment is added or removed. */ class ActivityStore( val fragmentStore: FragmentStore = FragmentStore.EMPTY, val streams: (StreamConfigurator.() -> Disposable)? = null, val configureActivity: ((Activity) -> Unit)? = null, + val onPreRenderFragmentState: ((Activity, FragmentState) -> Unit)? = null, val onRenderFragmentState: ((Activity, FragmentState) -> Unit)? = null, val onFragmentLifecycleEvent: ((FragmentLifecycleEvent) -> Unit)? = null ) diff --git a/formula-android/src/main/java/com/instacart/formula/android/internal/ActivityManager.kt b/formula-android/src/main/java/com/instacart/formula/android/internal/ActivityManager.kt index af00e8d9..09776678 100644 --- a/formula-android/src/main/java/com/instacart/formula/android/internal/ActivityManager.kt +++ b/formula-android/src/main/java/com/instacart/formula/android/internal/ActivityManager.kt @@ -57,6 +57,7 @@ internal class ActivityManager( val renderView = fragmentRenderView ?: throw callOnPreCreateException(activity) uiSubscription = delegate.fragmentState().subscribe { + store.onPreRenderFragmentState?.invoke(activity, it) renderView.render(it) store.onRenderFragmentState?.invoke(activity, it) }