diff --git a/formula-android/src/main/java/com/instacart/formula/android/FormulaFragment.kt b/formula-android/src/main/java/com/instacart/formula/android/FormulaFragment.kt index 96a3a2e3..8ca13898 100644 --- a/formula-android/src/main/java/com/instacart/formula/android/FormulaFragment.kt +++ b/formula-android/src/main/java/com/instacart/formula/android/FormulaFragment.kt @@ -7,7 +7,6 @@ import android.view.ViewGroup import androidx.fragment.app.Fragment import com.instacart.formula.FormulaAndroid import com.instacart.formula.android.internal.FormulaFragmentDelegate -import com.instacart.formula.android.internal.getFormulaFragmentId import com.instacart.formula.android.internal.getOrSetArguments import java.lang.Exception diff --git a/formula-android/src/main/java/com/instacart/formula/android/FragmentId.kt b/formula-android/src/main/java/com/instacart/formula/android/FragmentId.kt index 31016d10..174f9009 100644 --- a/formula-android/src/main/java/com/instacart/formula/android/FragmentId.kt +++ b/formula-android/src/main/java/com/instacart/formula/android/FragmentId.kt @@ -1,5 +1,9 @@ package com.instacart.formula.android +import androidx.fragment.app.Fragment +import com.instacart.formula.android.internal.getFragmentInstanceId +import com.instacart.formula.android.internal.getFragmentKey + /** * An object used to identify a fragment. It combines both a user generated [key] and * a generated [String] id. @@ -12,4 +16,14 @@ package com.instacart.formula.android data class FragmentId( val instanceId: String, val key: FragmentKey -) \ No newline at end of file +) + +/** + * Gets a [FragmentId] for a given [Fragment]. + */ +fun Fragment.getFormulaFragmentId(): FragmentId { + return FragmentId( + instanceId = getFragmentInstanceId(), + key = getFragmentKey() + ) +} \ No newline at end of file diff --git a/formula-android/src/main/java/com/instacart/formula/android/internal/FragmentFlowRenderView.kt b/formula-android/src/main/java/com/instacart/formula/android/internal/FragmentFlowRenderView.kt index da23b3df..ec3fb35c 100644 --- a/formula-android/src/main/java/com/instacart/formula/android/internal/FragmentFlowRenderView.kt +++ b/formula-android/src/main/java/com/instacart/formula/android/internal/FragmentFlowRenderView.kt @@ -16,6 +16,7 @@ import com.instacart.formula.android.BackCallback import com.instacart.formula.android.FeatureEvent import com.instacart.formula.android.FragmentId import com.instacart.formula.android.ViewFactory +import com.instacart.formula.android.getFormulaFragmentId import java.util.LinkedList /** diff --git a/formula-android/src/main/java/com/instacart/formula/android/internal/FragmentLifecycle.kt b/formula-android/src/main/java/com/instacart/formula/android/internal/FragmentLifecycle.kt index 5ea3d78e..1240e393 100644 --- a/formula-android/src/main/java/com/instacart/formula/android/internal/FragmentLifecycle.kt +++ b/formula-android/src/main/java/com/instacart/formula/android/internal/FragmentLifecycle.kt @@ -19,7 +19,7 @@ internal object FragmentLifecycle { } } -private fun Fragment.getFragmentKey(): FragmentKey { +internal fun Fragment.getFragmentKey(): FragmentKey { val fragment = this as? BaseFormulaFragment<*> return fragment?.getFragmentKey() ?: EmptyFragmentKey(tag.orEmpty()) } @@ -28,7 +28,7 @@ private fun Fragment.getFragmentKey(): FragmentKey { * Gets a persisted across configuration changes fragment identifier or initializes * one if it doesn't exist. */ -private fun Fragment.getFragmentInstanceId(): String { +internal fun Fragment.getFragmentInstanceId(): String { return if (this is BaseFormulaFragment<*>) { val arguments = getOrSetArguments() val id = arguments.getString(FormulaFragment.ARG_FORMULA_ID, "") @@ -42,13 +42,6 @@ private fun Fragment.getFragmentInstanceId(): String { } } -internal fun Fragment.getFormulaFragmentId(): FragmentId { - return FragmentId( - instanceId = getFragmentInstanceId(), - key = getFragmentKey() - ) -} - internal fun Fragment.getOrSetArguments(): Bundle { return arguments ?: run { Bundle().apply {