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

Allow Fragment::arg with nullable parameters. #420

Merged
merged 7 commits into from
Jul 27, 2022

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

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.

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 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