iamantoniodinuzzo / CineMates

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

Open iamantoniodinuzzo opened 2 weeks ago

iamantoniodinuzzo commented 2 weeks ago

Suggestion / Feature Request

  1. Use:
    <androidx.compose.ui.platform.ComposeView
        android:id="@+id/composeView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
       >

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.

  1. Create a Koltlin file and write equivalent compose code
  2. 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
        }
    }
    }