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

@Inject for findFragmentById? #35

Open
dsvensson opened this issue Jul 17, 2015 · 5 comments
Open

@Inject for findFragmentById? #35

dsvensson opened this issue Jul 17, 2015 · 5 comments

Comments

@dsvensson
Copy link

Not sure if it's possible, but it feels like something that would be nice to deal with an @InjectSomething tag. Perhaps with supportFragmentManager vs fragmentManager distinction.

Currently do this in my onCreate:

frag = supportFragmentManager.findFragmentById(R.id.frag_something) as SomeFragment
@eugene-kamenev
Copy link
Collaborator

I cant understand what you want to get. Can you please describe more in detail how it should work? You can post a complete class with your implementation and some comments in it to help us understand.
P.S. dont use 'as' operator too much, it will decrease performance.
Thanks.

@jmartinesp
Copy link
Owner

Hi. If I'm not mistaken what you want is to be able to inject a fragment from XML:

<fragment android:id="@+id/myFragment" class="...">

In the same way we do it for views. While I think this could be a good thing, I'm not sure it should be done in an annotation way, as it isn't a widely used feature. I thought about using a DSL method, but it doesn't make it less verbose:

fragment = (MyFragment) activity.findFragment(R.id.myFragment)

I don't know. What do you think, @eugene-kamenev?

@eugene-kamenev
Copy link
Collaborator

@Arasthel I think @dsvensson wants to define an additional parameter in annotation to use supportFragmentManager or fragmentManager am I wrong? :) just cant understand the goal

@dsvensson
Copy link
Author

@SomeAnnotationCompatOrSupportOrSomething(R.id.frag_something) 
SomeFragment foo

Instead of what I wrote above

@jmartinesp
Copy link
Owner

It could be done using just an annotation, as the AST transform could check if the activity/fragment is normal or compat. What I'm not really sure about is if it's worth the trouble of making the new transformation...

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

No branches or pull requests

3 participants