这是indexloc提供的服务,不要输入任何密码
Skip to content

fix bug in navigation: allow integer default types with argType float. #117

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

Closed
wants to merge 1 commit into from
Closed
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 @@ -167,6 +167,14 @@ class NavInflaterTest {
.isEqualTo(NavType.FloatType to 3.14f)
}

@Test
fun testDefaultIntArgumentsFloat() {
val defaultArguments = inflateDefaultArgumentsFromGraph()

assertThat(defaultArguments["test_int_as_float"]?.run { type to defaultValue })
.isEqualTo(NavType.FloatType to 3f)
}

@Test
fun testDefaultArgumentsBoolean() {
val defaultArguments = inflateDefaultArgumentsFromGraph()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
android:name="test_float"
android:defaultValue="3.14" />

<argument
android:name="test_int_as_float"
app:argType="float"
android:defaultValue="3" />

<argument
android:name="test_reference"
android:defaultValue="@style/AppTheme" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,15 @@ private NavArgument inflateArgument(@NonNull TypedArray a, @NonNull Resources re
default:
if (value.type >= TypedValue.TYPE_FIRST_INT
&& value.type <= TypedValue.TYPE_LAST_INT) {
navType = checkNavType(value, navType, NavType.IntType,
argType, "integer");
defaultValue = value.data;
if (navType == NavType.FloatType) {
navType = checkNavType(value, navType, NavType.FloatType,
argType, "float");
defaultValue = (float) value.data;
} else {
navType = checkNavType(value, navType, NavType.IntType,
argType, "integer");
defaultValue = value.data;
}
} else {
throw new XmlPullParserException(
"unsupported argument type " + value.type);
Expand Down