CineMates is a modern android application for movie fans in which you will be able to search for movies and consult information provided by The Movie DB.
GNU General Public License v3.0
15
stars
3
forks
source link
[Feature Request / Suggestion]: Converting XML to Compose #342
The ComposeView is a custom view provided by Jetpack Compose that allows us to embed Compose UI components within an Android XML layout. It serves as a container for hosting Compose content.
By using the ComposeView, we can leverage the power of Jetpack Compose to build dynamic and interactive user interfaces within the existing XML-based layout.
Create a Koltlin file and write equivalent compose code
Add this Kotlin compose file with the existing Fragment/Activity:
class RateAppFragment : Fragment(R.layout.fragment_rate_app) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState).apply {
composeView.setContent {
MaterialTheme(
colors = if (isSystemInDarkTheme()) {
darkColors(primary = Color(R.color.colorPrimary))
} else {
lightColors(primary = Color(R.color.colorPrimary))
},
content = {
// Your content here
RateAppScreen()
}
)
}
}
}
override fun onResume() {
super.onResume()
if (activity is MainActivity) {
(activity as MainActivity).toolbar.visibility = View.VISIBLE
(activity as MainActivity).toolbarTextView.text = getString(R.string.rate)
(activity as MainActivity).toolbarTextView.visibility = View.VISIBLE
}
}
}
Suggestion / Feature Request
The ComposeView is a custom view provided by Jetpack Compose that allows us to embed Compose UI components within an Android XML layout. It serves as a container for hosting Compose content.
By using the ComposeView, we can leverage the power of Jetpack Compose to build dynamic and interactive user interfaces within the existing XML-based layout.
Add this Kotlin compose file with the existing Fragment/Activity: