Skip to content

Commit

Permalink
Make getFormulaFragmentId() a public function. (#400)
Browse files Browse the repository at this point in the history
  • Loading branch information
Laimiux authored Oct 8, 2024
1 parent 520ca1c commit 2f1ff1d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -12,4 +16,14 @@ package com.instacart.formula.android
data class FragmentId(
val instanceId: String,
val key: FragmentKey
)
)

/**
* Gets a [FragmentId] for a given [Fragment].
*/
fun Fragment.getFormulaFragmentId(): FragmentId {
return FragmentId(
instanceId = getFragmentInstanceId(),
key = getFragmentKey()
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand All @@ -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, "")
Expand All @@ -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 {
Expand Down

0 comments on commit 2f1ff1d

Please sign in to comment.