Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make getFormulaFragmentId() a public function. #400

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every time someone calls this, it generates a new FragmentId object, which may be unexpected. Usually a get function doesn't allocate anything new, so this might be unexpected. But I don't know the usecase of this, so it could be fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a tiny data class, should be completely fine.

}
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
Loading