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

Can't access delegate in bridge component #86

Open
joemasilotti opened this issue Jan 15, 2025 · 6 comments
Open

Can't access delegate in bridge component #86

joemasilotti opened this issue Jan 15, 2025 · 6 comments

Comments

@joemasilotti
Copy link
Member

I've copy-pasted the following into an existing Hotwire Native Android app from the Bridge Components section of the guide.

package com.masilotti.hikingjournal.components

import androidx.fragment.app.Fragment
import dev.hotwire.core.bridge.BridgeComponent
import dev.hotwire.core.bridge.BridgeDelegate
import dev.hotwire.core.bridge.Message
import dev.hotwire.navigation.destinations.HotwireDestination

class ButtonComponent(
    name: String,
    private val delegate: BridgeDelegate<HotwireDestination>
) : BridgeComponent<HotwireDestination>(name, delegate) {
    private val fragment: Fragment
        get() = delegate.destination.fragment

    override fun onReceive(message: Message) {
        TODO("Not yet implemented")
    }
}

When I try to run the app it fails with the following error:

e: file://app/src/main/java/com/masilotti/hikingjournal/components/ButtonComponent.kt:9:7 Conflicting declarations:
val delegate: BridgeDelegate<HotwireDestination>

If I change private val delegate to delegate then I get the following error:

e: file:///app/src/main/java/com/masilotti/hikingjournal/components/ButtonComponent.kt:14:17 Cannot access 'val delegate: BridgeDelegate<HotwireDestination>':
it is private/*private to this*/ in 'com/masilotti/hikingjournal/components/ButtonComponent'.

I'm extra confused because if I copy paste this into a brand new Hotwire Native app I don't get the error. Same goes for the demo app.

Any ideas what could be causing this? I'm at a loss as to what I could have configured, or dependency I added, to change something so fundamental about Kotlin. I'm using Hotwire Native Android v1.1.1.

@jayohms
Copy link
Contributor

jayohms commented Jan 15, 2025

@joemasilotti is this by chance an older project? I wonder if updating your Android Gradle Plugin and Kotlin dependencies would help here? The Hotwire Native repo is running these versions:
https://github.com/hotwired/hotwire-native-android/blob/main/build.gradle.kts#L3-L6

To update AGP, you can go to Android Studio -> Tools -> AGP Upgrade Assistant

@jayohms
Copy link
Contributor

jayohms commented Jan 15, 2025

You can also try Project -> Rebuild Project and restarting Android Studio. I think this is a random compiler/cache issue.

@joemasilotti
Copy link
Member Author

Thanks Jay! It looks like Kotlin 2.0.0 might be the issue? Here's a new project with the Hotwire Native dependency, upgraded to Kotlin 2.0.0, and the code snippet above.

MyApplication.zip

Of note, upgrading the demo app to 2.0.0 does not seem to reproduce the issue, oddly.

@joemasilotti
Copy link
Member Author

This also makes me wonder if we should make delegate protected instead of private in BridgeComponent.

@williamkennedy
Copy link

I came across this issue yesterday when writing this

I assumed it was an issue with my compiler configuration, so I simply called the variable formDelegate to prevent the redeclaration issue.

class FormComponent(  
    name: String,  
    private val formDelegate: BridgeDelegate<HotwireDestination>  
) : BridgeComponent<HotwireDestination>(name, formDelegate) {
...
}

@joemasilotti
Copy link
Member Author

Oooh, good idea @williamkennedy! That works for me (for now).

I think it gives more power to my previous comment about making the property protected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants