Skip to content

Conversation

@oldwomanjosiah
Copy link
Contributor

@oldwomanjosiah oldwomanjosiah commented Jun 10, 2022

Remove the non-null restriction on Fragment::arg using an isInstance
check instead of the as? cast. This requires more type information at
runtime, so a Class<A> param is added as well as a convenience inline
function with reified type parameter.

I didn't see any tests for this function at the moment, so none were added. Just let me know if you would like this to change.

Binary incompatibility: Adds a new parameter to the only overload of arg visible from Java.

closes #414

@oldwomanjosiah oldwomanjosiah requested a review from RBusarow as a code owner June 10, 2022 00:03
Copy link
Owner

@RBusarow RBusarow left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. I've added tests, added an overload for argOrNull to handle args which are missing entirely, and removed the Java overload.

The CI wasn't executing because by default, GitHub does not run actions against PRs from forks until they've been allowed by a repo admin. Aaand I didn't notice that I needed to approve it. 🤷 Sorry about that.

* @param clazz type class expected for this argument
* @see FragmentInjectFactory for instantiating fragments with arguments
*/
public fun <A : Any?> Fragment.arg(bundleKey: String, clazz: Class<A>): Lazy<A> = lazy {
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not willing to introduce an overload for Java compatibility, considering that this library is tied to a Kotlin compiler plugin.

@RBusarow RBusarow force-pushed the josiah/update_arg branch from f16fcf1 to ff03ca7 Compare July 27, 2022 17:56
oldwomanjosiah and others added 5 commits July 27, 2022 12:56
Remove the non-null restriction on `Fragment::arg` using an `isInstance`
check instead of the `as?` cast. This requires more type information at
runtime, so a `Class<A>` param is added as well as a convenience inline
function with reified type parameter.
Update based on [this response](actions/checkout#551 (comment)).
This may not work for private repos.
- remove overloaded java version
- use KClass<*> type names for error messages (e.g., `kotlin.Int` vs `java.lang.Integer`)
- fill out kdoc
- add tests
@RBusarow RBusarow force-pushed the josiah/update_arg branch from ff03ca7 to 681bfe3 Compare July 27, 2022 17:56
@RBusarow RBusarow merged commit 36273b2 into RBusarow:main Jul 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nullable Parameter in Fragment.arg(...) causes IllegalStateException

2 participants