<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Eyimofe Ogunbiyi</title>
    <description>The latest articles on DEV Community by Eyimofe Ogunbiyi (@strawhatdeveloper).</description>
    <link>https://dev.to/strawhatdeveloper</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F805199%2Fdc2e1144-3573-4d07-8cae-69d5e6d06aa5.png</url>
      <title>DEV Community: Eyimofe Ogunbiyi</title>
      <link>https://dev.to/strawhatdeveloper</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/strawhatdeveloper"/>
    <language>en</language>
    <item>
      <title>Into the Compose-Verse, A beginner guide to Android Development With Jetpack Compose</title>
      <dc:creator>Eyimofe Ogunbiyi</dc:creator>
      <pubDate>Sun, 30 Jan 2022 07:51:58 +0000</pubDate>
      <link>https://dev.to/strawhatdeveloper/into-the-compose-verse-a-beginner-guide-to-android-development-with-jetpack-compose-48n0</link>
      <guid>https://dev.to/strawhatdeveloper/into-the-compose-verse-a-beginner-guide-to-android-development-with-jetpack-compose-48n0</guid>
      <description>&lt;h2&gt;
  
  
  Part 1: The very basics.
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What was&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Android development has been largely characterized by the view-based system of building android User interfaces. This approach involved defining UI elements and layouts as views in XML files, then rendering these views by inflating them, thus granting the user the ability to interact with them. The created views usually hold some state and views change the state depending on the user's interaction. &lt;/p&gt;

&lt;p&gt;The above system seems like a good way to build applications, why then did it have to change, well the view-based approach has a couple of problems today:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;It's very old.&lt;/strong&gt;  The Android view system was created over 10 years ago,  and as a result, its APIs have started to show signs of ageing, the programming paradigms which largely influenced the view system are less prominent today. One prominent example that shows the ageing of the view system, is the fact that the View class which represents the basic building block for user interface components is over 30,000 lines long. The android toolkit team has even stated that the amount of code in this class had become unmanageable and as such needed to change.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;User expectations for User Interfaces are growing.&lt;/strong&gt; The various demands users have of user interfaces have largely grown since the time the android view system was introduced. Users prefer UI with animations, motions and these things were not particularly important when the view system was being developed originally.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Complexity&lt;/strong&gt;. The view system involved writing the User Interface in XML, and the application logic in Java or Kotlin. This inevitably led to unintended complexity in managing the application. In addition to this, due to the nature of XML, we had to write longer lines of code to accomplish little things for example something as simple as changing the shape of a FAB or applying a gradient to a button would involve creating a drawable XML file and manually defining the gradient before applying it to our button.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No one likes XML ( I don't 😉)&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;What is&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To solve the issues, the Android UI team introduced Jetpack Compose. Jetpack compose is Android's modern toolkit for building native UI. It simplifies and accelerates UI development on android and allows us to quickly bring our app to life with less code and intuitive Kotlin APIs. &lt;/p&gt;

&lt;p&gt;Jetpack Compose is written entirely with Kotlin and offers us faster, simpler development in a single language, with fewer lines of code. It also comes with support with android studio and other jetpack items. Thus, our development speed is greatly increased. Jetpack Compose offers a declarative UI approach&lt;/p&gt;

&lt;p&gt;What problems does compose solve?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Separation of Concerns:&lt;/strong&gt; When using the view system, we usually have a tight coupling of various elements such as the application logic and the layout files. This can lead to unnecessary complexity in our code. When using jetpack compose both our layout and application logic is defined in the same language, the dependencies between our elements become more obvious as a result we can easily refactor and reduce the coupling of our elements together. Jetpack compose provides us with tools that allow us to better perform separation of concerns.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Brings the power of the kotlin language to our UI elements&lt;/strong&gt;. Since Jetpack Compose is purely kotlin, it allows us to use language-level primitives that kotlin provides to do things dynamically eg using if-else statements to render parts of the UI, or easily executing complicated UI logic. While this was possible using the View system, it was inherently more complicated, as it involved firstly defining all the UI elements in the XML file then finding those elements via Id or view binding in an activity or fragment then performing our control flow logic there. In jetpack compose, we can do all of this in a single file and with less code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Favors Composition over Inheritance.&lt;/strong&gt; The view system was built upon inheritance, all UI elements inherit from the view class, and we could extend inbuilt views to create our custom elements, but this gives rise to all the issues associated with inheritance. In Compose, there is no single parent that we have to inherit from, all of our Ui elements are made up of other UI elements which we can switch or modify as we like.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Views vs Compose
&lt;/h2&gt;

&lt;p&gt;Now that some of the theory is out of the way, let's look at a practical example of building a UI with the view system versus Jetpack Compose. We will be recreating the UI below with both the view system and Jetpack compose and then we can compare which one is more ideal, so let's get ready to rumble . . .&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IIZbSuWN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yhc6m34gzt5wvtljbbn9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IIZbSuWN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yhc6m34gzt5wvtljbbn9.png" alt="UI we will be building" width="420" height="948"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  View System
&lt;/h2&gt;

&lt;p&gt;To build the above UI using the view system, we will employ the following, &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Recycler View&lt;/li&gt;
&lt;li&gt;A custom View Adapter&lt;/li&gt;
&lt;li&gt;Google material card view&lt;/li&gt;
&lt;li&gt;Google Material Button&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 1: Layouts
&lt;/h3&gt;

&lt;p&gt;In our main activity XML, we add our recycler view and the necessary constraints&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt; 
&amp;lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity"&amp;gt; 
    &amp;lt;androidx.recyclerview.widget.RecyclerView 
        android:id="@+id/main_recycler_view" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        app:layout_constraintBottom_toBottomOf="parent" 
        app:layout_constraintLeft_toLeftOf="parent" 
        app:layout_constraintRight_toRightOf="parent" 
        app:layout_constraintTop_toTopOf="parent" /&amp;gt; 
&amp;lt;/androidx.constraintlayout.widget.ConstraintLayout&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, create a layout for each card that will be on our list&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt; 
&amp;lt;androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/meal_card" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:cardCornerRadius="10dp" 
    app:cardElevation="5dp" 
    app:cardUseCompatPadding="true"&amp;gt; 
    &amp;lt;LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical"&amp;gt; 
        &amp;lt;ImageView 
            android:id="@+id/meal_image" 
            android:layout_width="match_parent" 
            android:layout_height="150dp" 
            android:scaleType="centerCrop" 
            tools:src="@drawable/pizza" /&amp;gt; 
        &amp;lt;TextView 
            android:id="@+id/meal_name" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:paddingStart="10dp" 
            android:text="Hello world" 
            android:textSize="20sp" 
            android:textStyle="bold" /&amp;gt; 
        &amp;lt;LinearLayout 
            android:layout_width="match_parent" 
            android:layout_height="wrap_content" 
            android:gravity="bottom" 
            android:orientation="horizontal" 
            android:padding="10dp"&amp;gt; 
            &amp;lt;TextView 
                android:id="@+id/meal_time" 
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content" 
                android:text="5mins" 
                android:textSize="20sp" /&amp;gt; 
            &amp;lt;View 
                android:layout_width="10dp" 
                android:layout_height="match_parent" /&amp;gt; 
            &amp;lt;TextView 
                android:id="@+id/meal_ingredients" 
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content" 
                android:text="4 ingredients" 
                android:textSize="20sp" /&amp;gt; 
            &amp;lt;View 
                android:layout_width="15dp" 
                android:layout_height="match_parent" /&amp;gt; 
            &amp;lt;com.google.android.material.button.MaterialButton 
                style="@style/Widget.MaterialComponents.Button.OutlinedButton" 
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content" 
                android:background="@android:color/white" 
                android:drawableLeft="@drawable/ic_baseline_play_arrow" 
                android:drawableTint="@color/green" 
                android:text="cook" 
                android:textColor="@color/green" 
                android:textSize="15sp" 
                app:strokeColor="@color/green" 
                app:strokeWidth="20dp" /&amp;gt; 
        &amp;lt;/LinearLayout&amp;gt; 
    &amp;lt;/LinearLayout&amp;gt; 
&amp;lt;/androidx.cardview.widget.CardView&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Adapters
&lt;/h3&gt;

&lt;p&gt;Create a custom adapter that will be used for our recycler view&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MealAdapter() : RecyclerView.Adapter&amp;lt;MealAdapter.ViewHolder&amp;gt;() { 
    private var meals = emptyList&amp;lt;Meal&amp;gt;() 
    class ViewHolder(binding: MealCardBinding) : RecyclerView.ViewHolder(binding.root) { 
        val image = binding.mealImage 
        val name = binding.mealName 
        val time = binding.mealTime 
        val noIngredients = binding.mealIngredients 
    } 
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { 
        val binding: MealCardBinding = MealCardBinding.inflate( 
            LayoutInflater.from(parent.context), 
            parent, 
            false 
        ) 
        return ViewHolder(binding) 
    } 
    @SuppressLint("SetTextI18n") 
    override fun onBindViewHolder(holder: ViewHolder, position: Int) { 
        val meal = meals[position] 
        holder.image.setImageResource(meal.image) 
        holder.name.text = meal.name 
        holder.time.text = "${meal.time} minutes" 
        holder.noIngredients.text = "${meal.ingredients} ingredients" 
    } 
    override fun getItemCount(): Int { 
        return meals.size 
    } 
    @SuppressLint("NotifyDataSetChanged") 
    fun updateMeals(meals: List&amp;lt;Meal&amp;gt;) { 
        Log.i("test", meals.toString()) 
        this.meals = meals 
        notifyDataSetChanged() 
    } 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3:  View Models and State
&lt;/h3&gt;

&lt;p&gt;We need a view model which will hold the data that will be displayed in our UI as well as a state class that for convenience, we will preload with some meal objects&lt;/p&gt;

&lt;p&gt;The Meal model&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;data class Meal (val name: String, val time: Int, val ingredients: Int, val image: Int)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Meal state&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;data class MealState(
    val meals: List&amp;lt;Meal&amp;gt; = listOf(
        Meal(
            name = "Cooked Coconut Mussels",
            time = 5,
            ingredients = 4,
            image = R.drawable.cookedcoconutmussels
        ),
        Meal(
            name = "Banana and Mandarin Buns",
            time = 45,
            ingredients = 6,
            image = R.drawable.bananaandmandarinbuns
        ),
        Meal(name = "Strawberry Meal", time = 59, ingredients = 3, image = R.drawable.strawberries),
        Meal(
            name = "Pizza",
            time = 50,
            ingredients = 7,
            image = R.drawable.pizza
        )

    )
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Meal View model&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MealViewModel : ViewModel() { 
    private val _state = MutableLiveData(MealState()) 
    val state: LiveData&amp;lt;MealState&amp;gt; 
        get() = _state 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 4: Putting it all together
&lt;/h3&gt;

&lt;p&gt;In our main activity class, we set up our recycler view with our adapter, and observe our note state&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MainActivity : AppCompatActivity() { 
    private lateinit var binding: ActivityMainBinding 
    private val mealViewModel: MealViewModel by viewModels() 
    override fun onCreate(savedInstanceState: Bundle?) { 
        super.onCreate(savedInstanceState) 
        binding = ActivityMainBinding.inflate(layoutInflater) 
        setContentView(binding.root) 
        val adapter: MealAdapter = MealAdapter() 
        binding.mainRecyclerView.adapter = adapter 
        binding.mainRecyclerView.layoutManager = LinearLayoutManager(this) 
        mealViewModel.state.observe(this, Observer { mealState -&amp;gt; 
            adapter.updateMeals(mealState.meals) 
        }) 
    } 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The resulting UI looks like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--u7v2oeul--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1pru7gvby0qk8a882mpk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--u7v2oeul--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1pru7gvby0qk8a882mpk.png" alt="Image of the resulting UI made with the view system 1" width="880" height="1858"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RZX3LzVp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kpvregdekmvkml1mue9k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RZX3LzVp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kpvregdekmvkml1mue9k.png" alt="Image of the resulting UI made with the view system 2" width="880" height="1858"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Jetpack Compose
&lt;/h2&gt;

&lt;p&gt;To create a project with jetpack compose, open up Android Studio and select a new project and from the templates provided, select empty compose activity. This will generate a compose project for us with all the necessary dependencies setup.&lt;/p&gt;

&lt;p&gt;Jetpack compose allows us to create our User interface with Composables. These are simple functions that are annotated with @Composable.&lt;/p&gt;

&lt;p&gt;Once we have a composable function we can style or modify its behaviour with Modifiers. Modifiers are parameters we pass into the composable function which help us change how a composable is presented. &lt;br&gt;
We can use modifiers to do the following: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Change the composable's behaviour and appearance&lt;/li&gt;
&lt;li&gt;Add information like accessibility labels&lt;/li&gt;
&lt;li&gt;Add high-level interactions like making an element clickable, scrollable, draggable or zoomable.
They are quite similar to layout parameters in view based layouts.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To build our UI in jetpack compose, first add the following dependencies:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Jetpack compose View model dependencies, to manage our UI data&lt;/li&gt;
&lt;li&gt;Material Icons &lt;/li&gt;
&lt;li&gt;Glide to handle images easily&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Step 1: Add dependencies
&lt;/h3&gt;

&lt;p&gt;In the project, the Gradle file add the following to the build script&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    ext { 
        compose_version = '1.0.1' 
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next in the application Gradle file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  //compose dependencies 
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.4.0-beta01"
implementation "androidx.compose.material:material-icons-extended:$compose_version"
implementation "com.github.skydoves:landscapist-glide:1.4.5"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: View models and State
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;data class Meal( 
    val name: String, 
    val image: Int, 
    val ingredients: Int, 
    val time: Int 
)

data class MealState( 
    val recipes: List&amp;lt;Meal&amp;gt; = listOf( 
        Meal( 
            "Banana and Mandarin buns", 
            R.drawable.bananaandmandarinbuns, 
            5, 
            20 
        ), 
        Meal( 
            "Cooked Coconut Mussels", 
            R.drawable.cookedcoconutmussels, 
            7, 
            11 
        ), 
        Meal( 
            "Fancy", 
            R.drawable.feedimage2, 
            9, 
            11, 
        ), 
        Meal( 
            "Italian", 
            R.drawable.pizza, 
            4, 
            20 
        ), 
    ), 
)

class MealViewModel : ViewModel(){ 
    private val _state = mutableStateOf(MealState()) 
    val state = _state 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;:  In the view model, we are using mutable state instead of Live-data, this is because jetpack compose gives us a new state API which is similar to the live data API, however, we do not need to observe this state directly, Jetpack compose behind the scenes, subscribe any composable that reads from that state to any write operations emanating from that state. Thus, any composable that reads from the state object will be notified and redrawn with new data when modified.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Create The Meal Card Composable
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Composable 
fun MealCard( 
    meal: Meal, 
) { 
    Card(modifier = Modifier.height(250.dp)) {

        Column(modifier = Modifier.fillMaxSize()) { 
            Box( 
                modifier = Modifier 
                    .fillMaxHeight(fraction = 0.5f) 
                    .fillMaxWidth() 
            ) { 
                GlideImage( 
                    imageModel = meal.image, 
                    contentDescription = meal.name, 
                    modifier = Modifier 
                        .matchParentSize() 
                        .clip( 
                            RoundedCornerShape( 
                                topStart = 5.dp, 
                                topEnd = 5.dp 
                            ) 
                        ), 
                    contentScale = ContentScale.Crop 
                ) 
            } 
            Spacer(modifier = Modifier.width(10.dp)) 
            Column( 
                modifier = Modifier 
                    .fillMaxWidth() 
                    .padding(10.dp), 
                ) { 
                Text( 
                    text = meal.name, 
                    fontWeight = FontWeight(600), 
                    fontSize = 18.sp 
                ) 
                Spacer(modifier = Modifier.height(10.dp)) 
                Row( 
                    modifier = Modifier.fillMaxWidth(), 
                    horizontalArrangement = Arrangement.SpaceBetween, 
                    verticalAlignment = Alignment.CenterVertically 
                ) { 
                    Row( 
                    ) { 
                        Text(text = "${meal.time} minutes", color = Color.Black) 
                        Spacer(modifier = Modifier.width(10.dp)) 
                        Text(text = "${meal.ingredients} Ingredients", color = Color.Black) 
                    } 
                    OutlinedButton( 
                        onClick = {}, 
                        border = BorderStroke(1.dp, Color.Green) 
                    ) { 
                        Row(verticalAlignment = Alignment.CenterVertically) { 
                            Icon( 
                                imageVector = Icons.Outlined.PlayArrow, 
                                contentDescription = null, 
                                tint = Color.Green 
                            ) 
                            Text(text = "Cook", color = Color.Green) 
                        } 
                    } 
                } 
            } 
        } 
    } 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the Meal Card above, we use the inbuilt composables provided to build up our meal card composable, we also employ modifiers extensively to shape and style our custom composable to our desires. Some of the composables and modifiers we used above include &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Card: This is an inbuilt composable that comes with some default elevation and corner radius. &lt;/li&gt;
&lt;li&gt;Column: This arranges its content in a vertical column&lt;/li&gt;
&lt;li&gt;GlideImage: This the image composable from the glide library and it helps us display and style images&lt;/li&gt;
&lt;li&gt;Spacer: This simply creates some space between elements&lt;/li&gt;
&lt;li&gt;Row: This arranges its content in a horizontal row&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now to the best part,  with Jetpack Compose you do not need to worry about creating recycler views or adapters whenever you need to render dynamically sized lists, you can simply use the lazy column or lazy row composables as shown below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Composable 
fun App( 
    mealViewModel: MealViewModel = viewModel(), 
) { 
    val state = mealViewModel.state.value 
    LazyColumn(modifier = Modifier 
        .fillMaxSize() 
        .padding(20.dp)) { 
        items(state.recipes) { item: Meal -&amp;gt; 
            MealCard(meal = item) 
            Spacer(modifier = Modifier.height(16.dp)) 
        } 
    } 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 4: Put it all together in the main activity
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MainActivity : ComponentActivity() { 
    override fun onCreate(savedInstanceState: Bundle?) { 
        super.onCreate(savedInstanceState) 
        setContent { 
            JetpackComposeExampleTheme { 
                App() 
            } 
        } 
    } 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The resulting UI &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ai2PhHYY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2rz1znp0tnr39pct5a2r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ai2PhHYY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2rz1znp0tnr39pct5a2r.png" alt="Resulting UI Built with Jetpack compose 1" width="880" height="1858"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sKB8SZHl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kv9k6k57q03q22tkoqd1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sKB8SZHl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kv9k6k57q03q22tkoqd1.png" alt="Resulting UI Built with Jetpack compose 2" width="880" height="1858"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Verdict
&lt;/h2&gt;

&lt;p&gt;As we can see Jetpack compose offers us a way to build declarative UIs with a single language. It allows us to leverage the power of Kotlin to create complex UIs with fewer lines of code and frees us to focus on other aspects of our application. The composable annotation lets us &lt;br&gt;
build out our UI with distinct functions which we can swap out and manipulate as we please, and the state API provided with Jetpack compose provides us with an easier and more intuitive way of managing state within our applications.&lt;/p&gt;

&lt;p&gt;The Code samples used in this article be found here:&lt;br&gt;
&lt;a href="https://github.com/mofe64/IntoTheComposeVerse/tree/main/TheVeryBasics"&gt;Source Code&lt;/a&gt;&lt;/p&gt;

</description>
      <category>android</category>
      <category>jetpackcompose</category>
      <category>kotlin</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
