Hello everyone, i recently started my android deve...
# compose
t
Hello everyone, i recently started my android development journey by building a app in compose while developing that app i have to use a third party library(readium for Epub rendering) which provides fragment which are created through factory method i want to host those fragment in my compose Ui i tried 1. Using AndroidFragment but it takes bundle for argument but that library uses fragment so i had to create a intermediate fragment which accepts those bundle initialize that library fragment i don't know is it the right way to do it i didn't found many example for this similar scenario and how to use this composable properly how it works(example fragmentState) 2. I checked the views in compose documentation of android but it emphasis was on using AndroidBinding but it uses xml layout to inflate so i dropped that approach 3. While surfing i found i can host them in AndroidView composable like
Copy code
AndroidView(
        factory = {context->
            FragmentContainerView(context).apply {
                id = View.generateViewId()
                val fragmentManager = (context as FragmentActivity).supportFragmentManager
                fragmentManager.fragmentFactory = fragmenFactory
                val fragment = fragmentManager.fragmentFactory.instantiate(
                    context.classLoader,
                    EpubNavigatorFragment::class.java.name
                )
                fragmentManager.beginTransaction()
                    .replace(id,fragment)
                    .commit()
            }
        }
    )
public final fun createFragmentFactory(
    initialLocator: Locator?,
    readingOrder: List<Link>? = null,
    initialPreferences: EpubPreferences = EpubPreferences(),
    listener: EpubNavigatorFragment. Listener? = null,
    paginationListener: EpubNavigatorFragment. PaginationListener? = null,
    configuration: EpubNavigatorFragment. Configuration = EpubNavigatorFragment.Configuration()
): FragmentFactory
it did work but again i want to understand how this integration work with lifecycle and all of that and how can i use update lambda so in short i want to understand the integration between composable and fragment and how can i use them in my app where i want to implement a fragment class which uses factory method moreover for the listeners should i inherit them to CustomViewModel class and pass it's instance ps: i know basics of creating ui with xml and i am completely beginner so please overlook if i am being silly
c
I don't think I understand your question. Seems like everything works. "i want to understand the integration between composable and fragment" I mean, I think you basically have the gist of it there. Personally I'd look to see if you can forego fragments entirely and see if theres some compose epub library. i haven't touched fragments in like 5 years. i wouldn't waste your brainpower on them. just my 2 cents.
i haven't really tried any of these but it seems like this app does epub rendering with compose? https://github.com/Pool-Of-Tears/Myne and this is a library that does epub + compose https://github.com/sagar0-0/cpub
t
@Colton Idle Thanks for the rescue see yea it did work but for more functionalities i wanted to understand it and i did checked first two repositories earlier 1. uses jsoup 2. the developer left the work on that in midway 3. one seems reliable and i will try using it my app
👍 1