The problem is how to get the proper activity context to launch to get the Fragment Manager? From interoperability between Composables and Fragment point of view is this even possible?
@Keep
class Card @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null
) : FrameLayout( // or any other View you want
// don't forget to use context wrapper and to apply your own theme
ContextThemeWrapper(
context,
context.resources.newTheme().apply { applyStyle(R.style.FantasyTheme, true) }
),
attrs
), GamingHubView {
override fun initialize(data: Map<String, Any>?) {
// inflate a view or render views dynamically
// inflate(context, R.layout.view_card, this)
val transaction: FragmentTransaction =
(this.context as AppCompatActivity).supportFragmentManager.beginTransaction()
transaction.replace(
this.id,
BlankFragment.newInstance("", ""),
BlankFragment::class.simpleName
)
transaction.addToBackStack(null)
transaction.commit()
}
}
/**
* Get activity instance from desired context.
*/
fun getActivity(context: Context?): AppCompatActivity? {
if (context == null) return null
if (context is AppCompatActivity) return context
return if (context is ContextWrapper) getActivity(context.baseContext) else null
}