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

How to use with custom view? #63

Closed
dakuenjery opened this issue Feb 23, 2018 · 4 comments
Closed

How to use with custom view? #63

dakuenjery opened this issue Feb 23, 2018 · 4 comments

Comments

@dakuenjery
Copy link

I can inject dependencies in activities and fragments, but can I inject in custom view?

class AppInputView : SearchView {
    private val router: Krouter by inject() // Unresolved reference: inject

    init {
        this.onQuerySubmit {
            context.toast(it)

            this.onActionViewCollapsed()
            this.clearFocus()
        }
    }

    constructor(context: Context) : super(context)
    constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
    constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
}
@arnaudgiuliani
Copy link
Member

You can add the KoinComponent interface to your component, to unlock by inject() properties.

@dakuenjery
Copy link
Author

Yes. It works. Thank you for great product!

@amitelman
Copy link

can you please give an example on how to inject Service into a Custom View class ?

if my CustomView class extends FrameLayout, how can i use the KoinComponent interface?

Thanks a head

@jeziellago
Copy link

can you please give an example on how to inject Service into a Custom View class ?

if my CustomView class extends FrameLayout, how can i use the KoinComponent interface?

Thanks a head

Maybe this:

class MyCustomView(context: Context) : FrameLayout(context), KoinComponent {
  ...
}

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

No branches or pull requests

4 participants