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

[VMD-Compose] Fixed observe of a single field of a ViewModel without specifying an initial value explicitly. #158

Merged
merged 1 commit into from
Apr 6, 2023

Conversation

gbourassa
Copy link
Member

Description

In this case, reflection is used to call the getter. Calling it without any parameters doesn't work anymore, probably following an update of the Kotlin version at some point.
Adding the required param to the getter.

Motivation and Context

Attempting to observe a single field without an initial value (which is optional) resulted in a crash:


java.lang.IllegalArgumentException: Callable expects 1 arguments, but 0 were provided.
at kotlin.reflect.jvm.internal.calls.Caller$DefaultImpls.checkArguments(Caller.kt:20)
at kotlin.reflect.jvm.internal.calls.CallerImpl.checkArguments(CallerImpl.kt:15)
at kotlin.reflect.jvm.internal.calls.CallerImpl$Method$Instance.call(CallerImpl.kt:112)
at kotlin.reflect.jvm.internal.KCallableImpl.call(KCallableImpl.kt:108)
at com.mirego.trikot.viewmodels.declarative.compose.extensions.ViewModelExtensionsKt.observeAsState(ViewModelExtensions.kt:64)

How Has This Been Tested?

In a project.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

…specifying an initial value explicitly. (calling the getter now requires "this" as a param)
@gbourassa gbourassa merged commit 1c3ad31 into master Apr 6, 2023
@gbourassa gbourassa deleted the fix/vmd-compose-observe-field-crashfix branch April 6, 2023 19:50
npresseault added a commit that referenced this pull request May 17, 2023
Since #158 it was no longer possible to call observe as state using a KProperty0 (class property without a receiver).
We now properly support KProperty0 (class property) and KProperty1 (instance property with a receiver)

For reference
val kPropReceiver: KProperty0<Boolean> = viewModel::isHidden
val kProp: KProperty1<VMDViewModel, Boolean> = VMDViewModel::isHidden

KProperty2: extension function with a different receiver will not be supported.
npresseault added a commit that referenced this pull request May 17, 2023
Description
The exception thrown was:
Fatal Exception: java.lang.IllegalArgumentException: Callable expects 0 arguments, but 1 were provided.

Since #158 it was no longer possible to call observeAsState using a KProperty0 (instance property). We now properly support KProperty0 (instance property) and KProperty1 (class property with a receiver argument)

For reference

val kPropReceiver: KProperty0<Boolean> = viewModel::isHidden 
val kProp: KProperty1<VMDViewModel, Boolean> = VMDViewModel::isHidden
KProperty2: extension function with a different receiver will not be supported.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants