diff --git a/compose-destinations-codegen/src/main/java/com/ramcosta/composedestinations/codegen/commons/Constants.kt b/compose-destinations-codegen/src/main/java/com/ramcosta/composedestinations/codegen/commons/Constants.kt index 87b0ebb2..16b27462 100644 --- a/compose-destinations-codegen/src/main/java/com/ramcosta/composedestinations/codegen/commons/Constants.kt +++ b/compose-destinations-codegen/src/main/java/com/ramcosta/composedestinations/codegen/commons/Constants.kt @@ -64,21 +64,23 @@ val CORE_DIRECTION_NAV_GRAPH_SPEC = Importable("DirectionNavGraphSpec", "$CORE_P val CORE_TYPED_NAV_GRAPH_SPEC = Importable("TypedNavGraphSpec", "$CORE_PACKAGE_NAME.spec.TypedNavGraphSpec") val CORE_ACTIVITY_DESTINATION_SPEC = Importable("ActivityDestinationSpec", "$CORE_PACKAGE_NAME.spec.ActivityDestinationSpec") val CORE_DIRECTION_ACTIVITY_DESTINATION_SPEC = Importable("DirectionActivityDestinationSpec", "$CORE_PACKAGE_NAME.spec.DirectionActivityDestinationSpec") -val CORE_STRING_NAV_TYPE = Importable("DestinationsStringNavType", "$CORE_PACKAGE_NAME.navargs.primitives.DestinationsStringNavType") -val CORE_INT_NAV_TYPE = Importable("DestinationsIntNavType", "$CORE_PACKAGE_NAME.navargs.primitives.DestinationsIntNavType") -val CORE_BOOLEAN_NAV_TYPE = Importable("DestinationsBooleanNavType", "$CORE_PACKAGE_NAME.navargs.primitives.DestinationsBooleanNavType") -val CORE_FLOAT_NAV_TYPE = Importable("DestinationsFloatNavType", "$CORE_PACKAGE_NAME.navargs.primitives.DestinationsFloatNavType") -val CORE_LONG_NAV_TYPE = Importable("DestinationsLongNavType", "$CORE_PACKAGE_NAME.navargs.primitives.DestinationsLongNavType") -val CORE_LONG_ARRAY_NAV_TYPE = Importable("DestinationsLongArrayNavType", "$CORE_PACKAGE_NAME.navargs.primitives.array.DestinationsLongArrayNavType") -val CORE_BOOLEAN_ARRAY_NAV_TYPE = Importable("DestinationsBooleanArrayNavType", "$CORE_PACKAGE_NAME.navargs.primitives.array.DestinationsBooleanArrayNavType") -val CORE_INT_ARRAY_NAV_TYPE = Importable("DestinationsIntArrayNavType", "$CORE_PACKAGE_NAME.navargs.primitives.array.DestinationsIntArrayNavType") -val CORE_FLOAT_ARRAY_NAV_TYPE = Importable("DestinationsFloatArrayNavType", "$CORE_PACKAGE_NAME.navargs.primitives.array.DestinationsFloatArrayNavType") -val CORE_STRING_ARRAY_NAV_TYPE = Importable("DestinationsStringArrayNavType", "$CORE_PACKAGE_NAME.navargs.primitives.array.DestinationsStringArrayNavType") -val CORE_BOOLEAN_ARRAY_LIST_NAV_TYPE = Importable("DestinationsBooleanArrayListNavType", "$CORE_PACKAGE_NAME.navargs.primitives.arraylist.DestinationsBooleanArrayListNavType") -val CORE_FLOAT_ARRAY_LIST_NAV_TYPE = Importable("DestinationsFloatArrayListNavType", "$CORE_PACKAGE_NAME.navargs.primitives.arraylist.DestinationsFloatArrayListNavType") -val CORE_INT_ARRAY_LIST_NAV_TYPE = Importable("DestinationsIntArrayListNavType", "$CORE_PACKAGE_NAME.navargs.primitives.arraylist.DestinationsIntArrayListNavType") -val CORE_LONG_ARRAY_LIST_NAV_TYPE = Importable("DestinationsLongArrayListNavType", "$CORE_PACKAGE_NAME.navargs.primitives.arraylist.DestinationsLongArrayListNavType") -val CORE_STRING_ARRAY_LIST_NAV_TYPE = Importable("DestinationsStringArrayListNavType", "$CORE_PACKAGE_NAME.navargs.primitives.arraylist.DestinationsStringArrayListNavType") + +val CORE_STRING_NAV_TYPE = Importable("stringNavType", "$CORE_PACKAGE_NAME.navargs.primitives.stringNavType") +val CORE_INT_NAV_TYPE = Importable("intNavType", "$CORE_PACKAGE_NAME.navargs.primitives.intNavType") +val CORE_BOOLEAN_NAV_TYPE = Importable("booleanNavType", "$CORE_PACKAGE_NAME.navargs.primitives.booleanNavType") +val CORE_FLOAT_NAV_TYPE = Importable("floatNavType", "$CORE_PACKAGE_NAME.navargs.primitives.floatNavType") +val CORE_LONG_NAV_TYPE = Importable("longNavType", "$CORE_PACKAGE_NAME.navargs.primitives.longNavType") +val CORE_LONG_ARRAY_NAV_TYPE = Importable("longArrayNavType", "$CORE_PACKAGE_NAME.navargs.primitives.array.longArrayNavType") +val CORE_BOOLEAN_ARRAY_NAV_TYPE = Importable("booleanArrayNavType", "$CORE_PACKAGE_NAME.navargs.primitives.array.booleanArrayNavType") +val CORE_INT_ARRAY_NAV_TYPE = Importable("intArrayNavType", "$CORE_PACKAGE_NAME.navargs.primitives.array.intArrayNavType") +val CORE_FLOAT_ARRAY_NAV_TYPE = Importable("floatArrayNavType", "$CORE_PACKAGE_NAME.navargs.primitives.array.floatArrayNavType") +val CORE_STRING_ARRAY_NAV_TYPE = Importable("stringArrayNavType", "$CORE_PACKAGE_NAME.navargs.primitives.array.stringArrayNavType") +val CORE_BOOLEAN_ARRAY_LIST_NAV_TYPE = Importable("booleanArrayListNavType", "$CORE_PACKAGE_NAME.navargs.primitives.arraylist.booleanArrayListNavType") +val CORE_FLOAT_ARRAY_LIST_NAV_TYPE = Importable("floatArrayListNavType", "$CORE_PACKAGE_NAME.navargs.primitives.arraylist.floatArrayListNavType") +val CORE_INT_ARRAY_LIST_NAV_TYPE = Importable("intArrayListNavType", "$CORE_PACKAGE_NAME.navargs.primitives.arraylist.intArrayListNavType") +val CORE_LONG_ARRAY_LIST_NAV_TYPE = Importable("longArrayListNavType", "$CORE_PACKAGE_NAME.navargs.primitives.arraylist.longArrayListNavType") +val CORE_STRING_ARRAY_LIST_NAV_TYPE = Importable("stringArrayListNavType", "$CORE_PACKAGE_NAME.navargs.primitives.arraylist.stringArrayListNavType") + const val CORE_DIRECTION = "Direction" const val CORE_DESTINATION_ANIMATION_STYLE = "DestinationStyle.Animated" const val CORE_BOTTOM_SHEET_DESTINATION_STYLE = "DestinationStyleBottomSheet" diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsBooleanNavType.kt b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsBooleanNavType.kt index 9a6692f8..776f70cd 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsBooleanNavType.kt +++ b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsBooleanNavType.kt @@ -4,7 +4,9 @@ import android.os.Bundle import androidx.lifecycle.SavedStateHandle import com.ramcosta.composedestinations.navargs.DestinationsNavType -object DestinationsBooleanNavType : DestinationsNavType() { +val booleanNavType: DestinationsNavType = DestinationsBooleanNavType + +internal object DestinationsBooleanNavType : DestinationsNavType() { override fun put(bundle: Bundle, key: String, value: Boolean?) { when (val bundleValue = booleanToBundleValue(value)) { diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsFloatNavType.kt b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsFloatNavType.kt index 06ceb217..8ebcc1a0 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsFloatNavType.kt +++ b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsFloatNavType.kt @@ -4,7 +4,9 @@ import android.os.Bundle import androidx.lifecycle.SavedStateHandle import com.ramcosta.composedestinations.navargs.DestinationsNavType -object DestinationsFloatNavType : DestinationsNavType() { +val floatNavType: DestinationsNavType = DestinationsFloatNavType + +internal object DestinationsFloatNavType : DestinationsNavType() { override fun put(bundle: Bundle, key: String, value: Float?) { when (val bundleValue = floatToBundleValue(value)) { diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsIntNavType.kt b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsIntNavType.kt index 2186c8fc..e5b0f52c 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsIntNavType.kt +++ b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsIntNavType.kt @@ -4,7 +4,9 @@ import android.os.Bundle import androidx.lifecycle.SavedStateHandle import com.ramcosta.composedestinations.navargs.DestinationsNavType -object DestinationsIntNavType : DestinationsNavType() { +val intNavType: DestinationsNavType = DestinationsIntNavType + +internal object DestinationsIntNavType : DestinationsNavType() { override fun put(bundle: Bundle, key: String, value: Int?) { when (val bundleValue = intToBundleValue(value)) { diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsLongNavType.kt b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsLongNavType.kt index 37e72dbf..c2fca834 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsLongNavType.kt +++ b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsLongNavType.kt @@ -4,7 +4,9 @@ import android.os.Bundle import androidx.lifecycle.SavedStateHandle import com.ramcosta.composedestinations.navargs.DestinationsNavType -object DestinationsLongNavType : DestinationsNavType() { +val longNavType: DestinationsNavType = DestinationsLongNavType + +internal object DestinationsLongNavType : DestinationsNavType() { override fun put(bundle: Bundle, key: String, value: Long?) { when (val bundleValue = longToBundleValue(value)) { diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsStringNavType.kt b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsStringNavType.kt index bc361142..11e53784 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsStringNavType.kt +++ b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsStringNavType.kt @@ -5,6 +5,8 @@ import androidx.lifecycle.SavedStateHandle import com.ramcosta.composedestinations.navargs.DestinationsNavType import com.ramcosta.composedestinations.navargs.utils.encodeForRoute +val stringNavType: DestinationsStringNavType = DestinationsStringNavType + object DestinationsStringNavType : DestinationsNavType() { internal const val ENCODED_EMPTY_STRING = "%02%03" diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsBooleanArrayNavType.kt b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsBooleanArrayNavType.kt index 9bd7a735..70d7b3c2 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsBooleanArrayNavType.kt +++ b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsBooleanArrayNavType.kt @@ -7,7 +7,9 @@ import com.ramcosta.composedestinations.navargs.primitives.DECODED_NULL import com.ramcosta.composedestinations.navargs.primitives.ENCODED_NULL import com.ramcosta.composedestinations.navargs.primitives.encodedComma -object DestinationsBooleanArrayNavType : DestinationsNavType() { +val booleanArrayNavType: DestinationsNavType = DestinationsBooleanArrayNavType + +internal object DestinationsBooleanArrayNavType : DestinationsNavType() { override fun put(bundle: Bundle, key: String, value: BooleanArray?) { bundle.putBooleanArray(key, value) diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsFloatArrayNavType.kt b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsFloatArrayNavType.kt index 984b4f51..e94ae958 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsFloatArrayNavType.kt +++ b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsFloatArrayNavType.kt @@ -7,7 +7,9 @@ import com.ramcosta.composedestinations.navargs.primitives.DECODED_NULL import com.ramcosta.composedestinations.navargs.primitives.ENCODED_NULL import com.ramcosta.composedestinations.navargs.primitives.encodedComma -object DestinationsFloatArrayNavType : DestinationsNavType() { +val floatArrayNavType: DestinationsNavType = DestinationsFloatArrayNavType + +internal object DestinationsFloatArrayNavType : DestinationsNavType() { override fun put(bundle: Bundle, key: String, value: FloatArray?) { bundle.putFloatArray(key, value) diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsIntArrayNavType.kt b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsIntArrayNavType.kt index a2b73cf7..fa4bc876 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsIntArrayNavType.kt +++ b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsIntArrayNavType.kt @@ -7,7 +7,9 @@ import com.ramcosta.composedestinations.navargs.primitives.DECODED_NULL import com.ramcosta.composedestinations.navargs.primitives.ENCODED_NULL import com.ramcosta.composedestinations.navargs.primitives.encodedComma -object DestinationsIntArrayNavType : DestinationsNavType() { +val intArrayNavType: DestinationsNavType = DestinationsIntArrayNavType + +internal object DestinationsIntArrayNavType : DestinationsNavType() { override fun put(bundle: Bundle, key: String, value: IntArray?) { bundle.putIntArray(key, value) diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsLongArrayNavType.kt b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsLongArrayNavType.kt index 6964318b..63ebdf85 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsLongArrayNavType.kt +++ b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsLongArrayNavType.kt @@ -7,7 +7,9 @@ import com.ramcosta.composedestinations.navargs.primitives.DECODED_NULL import com.ramcosta.composedestinations.navargs.primitives.ENCODED_NULL import com.ramcosta.composedestinations.navargs.primitives.encodedComma -object DestinationsLongArrayNavType : DestinationsNavType() { +val longArrayNavType: DestinationsNavType = DestinationsLongArrayNavType + +internal object DestinationsLongArrayNavType : DestinationsNavType() { override fun put(bundle: Bundle, key: String, value: LongArray?) { bundle.putLongArray(key, value) diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsStringArrayNavType.kt b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsStringArrayNavType.kt index 2109efb8..cc5b51c7 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsStringArrayNavType.kt +++ b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsStringArrayNavType.kt @@ -9,7 +9,9 @@ import com.ramcosta.composedestinations.navargs.primitives.ENCODED_NULL import com.ramcosta.composedestinations.navargs.primitives.encodedComma import com.ramcosta.composedestinations.navargs.utils.encodeForRoute -object DestinationsStringArrayNavType : DestinationsNavType?>() { +val stringArrayNavType: DestinationsNavType?> = DestinationsStringArrayNavType + +internal object DestinationsStringArrayNavType : DestinationsNavType?>() { override fun put(bundle: Bundle, key: String, value: Array?) { bundle.putStringArray(key, value) diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsBooleanArrayListNavType.kt b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsBooleanArrayListNavType.kt index d35abf5e..91c48c71 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsBooleanArrayListNavType.kt +++ b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsBooleanArrayListNavType.kt @@ -7,7 +7,9 @@ import com.ramcosta.composedestinations.navargs.primitives.DECODED_NULL import com.ramcosta.composedestinations.navargs.primitives.ENCODED_NULL import com.ramcosta.composedestinations.navargs.primitives.encodedComma -object DestinationsBooleanArrayListNavType : DestinationsNavType?>() { +val booleanArrayListNavType: DestinationsNavType?> = DestinationsBooleanArrayListNavType + +internal object DestinationsBooleanArrayListNavType : DestinationsNavType?>() { override fun put(bundle: Bundle, key: String, value: ArrayList?) { bundle.putBooleanArray(key, value.toArray()) diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsFloatArrayListNavType.kt b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsFloatArrayListNavType.kt index 418ca804..f661119d 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsFloatArrayListNavType.kt +++ b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsFloatArrayListNavType.kt @@ -7,7 +7,9 @@ import com.ramcosta.composedestinations.navargs.primitives.DECODED_NULL import com.ramcosta.composedestinations.navargs.primitives.ENCODED_NULL import com.ramcosta.composedestinations.navargs.primitives.encodedComma -object DestinationsFloatArrayListNavType : DestinationsNavType?>() { +val floatArrayListNavType: DestinationsNavType?> = DestinationsFloatArrayListNavType + +internal object DestinationsFloatArrayListNavType : DestinationsNavType?>() { override fun put(bundle: Bundle, key: String, value: ArrayList?) { bundle.putFloatArray(key, value.toArray()) diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsIntArrayListNavType.kt b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsIntArrayListNavType.kt index 89b6eadc..5a4bf027 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsIntArrayListNavType.kt +++ b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsIntArrayListNavType.kt @@ -7,7 +7,9 @@ import com.ramcosta.composedestinations.navargs.primitives.DECODED_NULL import com.ramcosta.composedestinations.navargs.primitives.ENCODED_NULL import com.ramcosta.composedestinations.navargs.primitives.encodedComma -object DestinationsIntArrayListNavType : DestinationsNavType?>() { +val intArrayListNavType: DestinationsNavType?> = DestinationsIntArrayListNavType + +internal object DestinationsIntArrayListNavType : DestinationsNavType?>() { override fun put(bundle: Bundle, key: String, value: ArrayList?) { bundle.putIntegerArrayList(key, value) diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsLongArrayListNavType.kt b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsLongArrayListNavType.kt index 1faf07e6..b9c1bcc8 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsLongArrayListNavType.kt +++ b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsLongArrayListNavType.kt @@ -7,7 +7,9 @@ import com.ramcosta.composedestinations.navargs.primitives.DECODED_NULL import com.ramcosta.composedestinations.navargs.primitives.ENCODED_NULL import com.ramcosta.composedestinations.navargs.primitives.encodedComma -object DestinationsLongArrayListNavType : DestinationsNavType?>() { +val longArrayListNavType: DestinationsNavType?> = DestinationsLongArrayListNavType + +internal object DestinationsLongArrayListNavType : DestinationsNavType?>() { override fun put(bundle: Bundle, key: String, value: ArrayList?) { bundle.putLongArray(key, value.toArray()) diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsStringArrayListNavType.kt b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsStringArrayListNavType.kt index 0bb559d1..117468ca 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsStringArrayListNavType.kt +++ b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsStringArrayListNavType.kt @@ -9,7 +9,9 @@ import com.ramcosta.composedestinations.navargs.primitives.ENCODED_NULL import com.ramcosta.composedestinations.navargs.primitives.encodedComma import com.ramcosta.composedestinations.navargs.utils.encodeForRoute -object DestinationsStringArrayListNavType : DestinationsNavType?>() { +val stringArrayListNavType: DestinationsNavType?> = DestinationsStringArrayListNavType + +internal object DestinationsStringArrayListNavType : DestinationsNavType?>() { override fun put(bundle: Bundle, key: String, value: ArrayList?) { bundle.putStringArrayList(key, value) diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/scope/DestinationScope.kt b/compose-destinations/src/main/java/com/ramcosta/composedestinations/scope/DestinationScope.kt index c90edc2e..cd5910d4 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/scope/DestinationScope.kt +++ b/compose-destinations/src/main/java/com/ramcosta/composedestinations/scope/DestinationScope.kt @@ -7,6 +7,11 @@ import androidx.compose.runtime.Immutable import androidx.navigation.NavBackStackEntry import androidx.navigation.NavController import com.ramcosta.composedestinations.navargs.DestinationsNavType +import com.ramcosta.composedestinations.navargs.primitives.DestinationsBooleanNavType +import com.ramcosta.composedestinations.navargs.primitives.DestinationsFloatNavType +import com.ramcosta.composedestinations.navargs.primitives.DestinationsIntNavType +import com.ramcosta.composedestinations.navargs.primitives.DestinationsLongNavType +import com.ramcosta.composedestinations.navargs.primitives.DestinationsStringNavType import com.ramcosta.composedestinations.navigation.DestinationDependenciesContainer import com.ramcosta.composedestinations.navigation.DestinationsNavigator import com.ramcosta.composedestinations.result.ResultBackNavigator @@ -15,6 +20,7 @@ import com.ramcosta.composedestinations.result.resultBackNavigator import com.ramcosta.composedestinations.result.resultRecipient import com.ramcosta.composedestinations.spec.DestinationSpec import com.ramcosta.composedestinations.spec.TypedDestinationSpec +import kotlin.reflect.KClass /** * Scope where a destination screen will be called in. @@ -108,3 +114,44 @@ interface AnimatedDestinationScope : DestinationScope, AnimatedVisibilityS */ @Immutable interface BottomSheetDestinationScope : DestinationScope, ColumnScope + +//region deprecated +@Suppress("DeprecatedCallableAddReplaceWith") +@Deprecated( + level = DeprecationLevel.ERROR, + message = "\n" + + "Use the `resultRecipient` version that takes in a `DestinationsNavType` parameter!\n" + + "Example: for Boolean results, it's `booleanNavType`, for custom types it's `customTypeClassNameNavType`." +) +@Composable +inline fun + DestinationScopeWithNoDependencies<*>.resultRecipient(): ResultRecipient = + resultRecipient(tryGettingNavType(T::class)) + +@Suppress("DeprecatedCallableAddReplaceWith") +@Deprecated( + level = DeprecationLevel.ERROR, + message = "\n" + + "Use the `resultBackNavigator` version that takes in a `DestinationsNavType` parameter!\n" + + "Example: for Boolean results, it's `booleanNavType`, for custom types it's `customTypeClassNameNavType`." +) +@Composable +inline fun DestinationScopeWithNoDependencies<*>.resultBackNavigator(): ResultBackNavigator = + resultBackNavigator(tryGettingNavType(T::class)) + +@PublishedApi +@Suppress("UNCHECKED_CAST") +internal fun tryGettingNavType(kClass: KClass): DestinationsNavType { + return when (kClass) { + String::class -> DestinationsStringNavType + Boolean::class -> DestinationsBooleanNavType + Float::class -> DestinationsFloatNavType + Int::class -> DestinationsIntNavType + Long::class -> DestinationsLongNavType + else -> error( + "Use the `resultBackNavigator`/`resultRecipient` version that takes in a `DestinationsNavType` parameter!\n" + + "Example: for Boolean results, it's `booleanNavType`, for custom types it's `customTypeClassNameNavType`." + ) + } as DestinationsNavType +} +// diff --git a/playground/app/src/main/java/com/ramcosta/samples/playground/AppNavigation.kt b/playground/app/src/main/java/com/ramcosta/samples/playground/AppNavigation.kt index d7448315..d95f7d0a 100644 --- a/playground/app/src/main/java/com/ramcosta/samples/playground/AppNavigation.kt +++ b/playground/app/src/main/java/com/ramcosta/samples/playground/AppNavigation.kt @@ -20,7 +20,7 @@ import com.ramcosta.composedestinations.bottomsheet.utils.bottomSheetComposable import com.ramcosta.composedestinations.generated.featurey.navtype.internalBackResultNavType import com.ramcosta.composedestinations.manualcomposablecalls.ManualComposableCallsBuilder import com.ramcosta.composedestinations.manualcomposablecalls.composable -import com.ramcosta.composedestinations.navargs.primitives.DestinationsBooleanNavType +import com.ramcosta.composedestinations.navargs.primitives.booleanNavType import com.ramcosta.composedestinations.navigation.dependency import com.ramcosta.composedestinations.navigation.destination import com.ramcosta.composedestinations.navigation.getBackStackEntry @@ -111,7 +111,7 @@ private fun ManualComposableCallsBuilder.greetingScreen( uiEvents = vm as GreetingUiEvents, uiState = vm as GreetingUiState, test = "testing param from NavHost", - resultRecipient = resultRecipient(DestinationsBooleanNavType), + resultRecipient = resultRecipient(booleanNavType), featYResult = resultRecipient(internalBackResultNavType), ) } @@ -143,7 +143,7 @@ fun SampleAppAnimatedNavHostExample( drawerController = drawerController, uiEvents = vm as GreetingUiEvents, uiState = vm as GreetingUiState, - resultRecipient = resultRecipient(DestinationsBooleanNavType), + resultRecipient = resultRecipient(booleanNavType), featYResult = resultRecipient(internalBackResultNavType), testProfileDeepLink = testProfileDeepLink, test = "testing param from NavHost", @@ -156,7 +156,7 @@ fun SampleAppAnimatedNavHostExample( dialogComposable(GoToProfileConfirmationDestination) { GoToProfileConfirmation( - resultNavigator = resultBackNavigator(navController, DestinationsBooleanNavType) + resultNavigator = resultBackNavigator(navController, booleanNavType) ) }