abstract class NavType<T : Any?>

Known direct subclasses
CollectionNavType

A NavType for Collection such as arrays, lists, maps.

NavType.ParcelableArrayType

ParcelableArrayType is used for NavArguments which hold arrays of Parcelables.

NavType.ParcelableType

ParcelableType is used for passing Parcelables in NavArguments.

NavType.SerializableArrayType

SerializableArrayType is used for NavArguments that hold arrays of Serializables.

NavType.SerializableType

SerializableType is used for Serializable NavArguments.

Known indirect subclasses
NavType.EnumType

EnumType is used for NavArguments holding enum values.


NavType denotes the type that can be used in a NavArgument.

There are built-in NavTypes for primitive types, such as int, long, boolean, float, and strings, parcelable, and serializable classes (including Enums), as well as arrays of each supported type.

You should only use one of the static NavType instances and subclasses defined in this class.

Parameters
<T : Any?>

the type of the data that is supported by this NavType

Summary

Nested types

EnumType is used for NavArguments holding enum values.

ParcelableArrayType is used for NavArguments which hold arrays of Parcelables.

ParcelableType is used for passing Parcelables in NavArguments.

SerializableArrayType is used for NavArguments that hold arrays of Serializables.

SerializableType is used for Serializable NavArguments.

Public companion functions

open NavType<*>
fromArgType(type: String?, packageName: String?)

Parse an argType string into a NavType.

Public companion properties

NavType<BooleanArray?>

NavType for storing boolean arrays, corresponding with the "boolean[]" type in a Navigation XML file.

NavType<List<Boolean>?>

NavType for storing list of Booleans.

NavType<Boolean>

NavType for storing boolean values, corresponding with the "boolean" type in a Navigation XML file.

NavType<FloatArray?>

NavType for storing float arrays, corresponding with the "float[]" type in a Navigation XML file.

NavType<List<Float>?>

NavType for storing list of Floats.

NavType<Float>

NavType for storing float values, corresponding with the "float" type in a Navigation XML file.

NavType<IntArray?>

NavType for storing integer arrays, corresponding with the "integer[]" type in a Navigation XML file.

NavType<List<Int>?>

NavType for storing list of Ints.

NavType<Int>

NavType for storing integer values, corresponding with the "integer" type in a Navigation XML file.

NavType<LongArray?>

NavType for storing long arrays, corresponding with the "long[]" type in a Navigation XML file.

NavType<List<Long>?>

NavType for storing list of Longs.

NavType<Long>

NavType for storing long values, corresponding with the "long" type in a Navigation XML file.

NavType<Int>

NavType for storing integer values representing resource ids, corresponding with the "reference" type in a Navigation XML file.

NavType<Array<String>?>

NavType for storing String arrays, corresponding with the "string[]" type in a Navigation XML file.

NavType<List<String>?>

NavType for storing list of Strings.

NavType<String?>

NavType for storing String values, corresponding with the "string" type in a Navigation XML file.

Public constructors

<T : Any?> NavType(isNullableAllowed: Boolean)

Public functions

abstract operator T?
get(bundle: SavedState, key: String)

Get a value of this type from the bundle

abstract T

Parse a value of this type from a String.

open T
parseValue(value: String, previousValue: T)

Parse a value of this type from a String and then combine that parsed value with the given previousValue of the same type to provide a new value that contains both the new and previous value.

abstract Unit
put(bundle: SavedState, key: String, value: T)

Put a value of this type in the bundle

open String
serializeAsValue(value: T)

Serialize a value of this NavType into a String.

open String
open Boolean
valueEquals(value: T, other: T)

Compares two values of type T and returns true if values are equal.

Public properties

open Boolean

Check if an argument with this type can hold a null value.

open String

The name of this type.

Public companion functions

fromArgType

Added in 2.4.0
open fun fromArgType(type: String?, packageName: String?): NavType<*>

Parse an argType string into a NavType.

Parameters
type: String?

argType string, usually parsed from the Navigation XML file

packageName: String?

package name of the R file, used for parsing relative class names starting with a dot.

Returns
NavType<*>

a NavType representing the type indicated by the argType string. Defaults to StringType for null.

Throws
kotlin.IllegalArgumentException

if there is no valid argType

kotlin.RuntimeException

if the type class name cannot be found

Public companion properties

BoolArrayType

val BoolArrayTypeNavType<BooleanArray?>

NavType for storing boolean arrays, corresponding with the "boolean[]" type in a Navigation XML file.

Null values are supported. Default values in Navigation XML files are not supported.

BoolListType

val BoolListTypeNavType<List<Boolean>?>

NavType for storing list of Booleans.

Null values are supported. List NavTypes in Navigation XML files are not supported.

BoolType

val BoolTypeNavType<Boolean>

NavType for storing boolean values, corresponding with the "boolean" type in a Navigation XML file.

Null values are not supported.

FloatArrayType

val FloatArrayTypeNavType<FloatArray?>

NavType for storing float arrays, corresponding with the "float[]" type in a Navigation XML file.

Null values are supported. Default values in Navigation XML files are not supported.

FloatListType

val FloatListTypeNavType<List<Float>?>

NavType for storing list of Floats.

Null values are supported. List NavTypes in Navigation XML files are not supported.

FloatType

val FloatTypeNavType<Float>

NavType for storing float values, corresponding with the "float" type in a Navigation XML file.

Null values are not supported.

IntArrayType

val IntArrayTypeNavType<IntArray?>

NavType for storing integer arrays, corresponding with the "integer[]" type in a Navigation XML file.

Null values are supported. Default values in Navigation XML files are not supported.

IntListType

val IntListTypeNavType<List<Int>?>

NavType for storing list of Ints.

Null values are supported. List NavTypes in Navigation XML files are not supported.

IntType

val IntTypeNavType<Int>

NavType for storing integer values, corresponding with the "integer" type in a Navigation XML file.

Null values are not supported.

LongArrayType

val LongArrayTypeNavType<LongArray?>

NavType for storing long arrays, corresponding with the "long[]" type in a Navigation XML file.

Null values are supported. Default values in Navigation XML files are not supported.

LongListType

val LongListTypeNavType<List<Long>?>

NavType for storing list of Longs.

Null values are supported. List NavTypes in Navigation XML files are not supported.

LongType

val LongTypeNavType<Long>

NavType for storing long values, corresponding with the "long" type in a Navigation XML file.

Null values are not supported. Default values for this type in Navigation XML files must always end with an 'L' suffix, e.g. app:defaultValue="123L".

ReferenceType

val ReferenceTypeNavType<Int>

NavType for storing integer values representing resource ids, corresponding with the "reference" type in a Navigation XML file.

Null values are not supported.

StringArrayType

val StringArrayTypeNavType<Array<String>?>

NavType for storing String arrays, corresponding with the "string[]" type in a Navigation XML file.

Null values are supported. Default values in Navigation XML files are not supported.

StringListType

val StringListTypeNavType<List<String>?>

NavType for storing list of Strings.

Null values are supported. List NavTypes in Navigation XML files are not supported.

StringType

val StringTypeNavType<String?>

NavType for storing String values, corresponding with the "string" type in a Navigation XML file.

Null values are supported.

Public constructors

<T : Any?> NavType(isNullableAllowed: Boolean)
Parameters
<T : Any?>

the type of the data that is supported by this NavType

isNullableAllowed: Boolean

whether an argument with this type can hold a null value.

Public functions

get

abstract operator fun get(bundle: SavedState, key: String): T?

Get a value of this type from the bundle

Parameters
bundle: SavedState

SavedState to get value from

key: String

SavedState key

Returns
T?

value of this type

parseValue

Added in 1.0.0
abstract fun parseValue(value: String): T

Parse a value of this type from a String.

Parameters
value: String

string representation of a value of this type

Returns
T

parsed value of the type represented by this NavType

Throws
kotlin.IllegalArgumentException

if value cannot be parsed into this type

parseValue

Added in 2.6.0
open fun parseValue(value: String, previousValue: T): T

Parse a value of this type from a String and then combine that parsed value with the given previousValue of the same type to provide a new value that contains both the new and previous value.

By default, the given value will replace the previousValue.

Parameters
value: String

string representation of a value of this type

previousValue: T

previously parsed value of this type

Returns
T

combined parsed value of the type represented by this NavType

Throws
kotlin.IllegalArgumentException

if value cannot be parsed into this type

put

abstract fun put(bundle: SavedState, key: String, value: T): Unit

Put a value of this type in the bundle

Parameters
bundle: SavedState

SavedState to put value in

key: String

SavedState key

value: T

value of this type

serializeAsValue

Added in 2.6.0
open fun serializeAsValue(value: T): String

Serialize a value of this NavType into a String.

By default it returns value of kotlin.toString or null if value passed in is null.

This method can be override for custom serialization implementation on types such custom NavType classes.

Note: Final output should be encoded with Uri.encode

Parameters
value: T

a value representing this NavType to be serialized into a String

Returns
String

encoded and serialized String value of value

toString

open fun toString(): String

valueEquals

Added in 2.8.0
open fun valueEquals(value: T, other: T): Boolean

Compares two values of type T and returns true if values are equal.

Parameters
value: T

the first value for comparison

other: T

the second value for comparison

Public properties

isNullableAllowed

Added in 1.0.0
open val isNullableAllowedBoolean

Check if an argument with this type can hold a null value.

Returns
Boolean

Returns true if this type allows null values, false otherwise.

name

Added in 1.0.0
open val nameString

The name of this type.

This is the same value that is used in Navigation XML argType attribute.

Returns
String

name of this type