Skip to content

Instantly share code, notes, and snippets.

View GibsonRuitiari's full-sized avatar
🤯

Ruitiari GibsonRuitiari

🤯
View GitHub Profile
@GibsonRuitiari
GibsonRuitiari / Main.kt
Last active June 4, 2022 20:47
mapNotNullTo Example
fun main() {
val stringListA = listOf(1,2,3,4,null)
val stringListContainer = mutableListOf<Int>()
// stringListA.mapNotNullTo(stringListContainer){ it?.times(2)}
// de-duplicate
val listAIterator = stringListA.iterator()
while (listAIterator.hasNext()){
val element = listAIterator.next()
element?.times(2)?.let {
stringListContainer.add(it)
package com.gibsonruitiari.eatoutui
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.*
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
package com.gibsonruitiari.eatoutui
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.*
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
public final class MainKt {
public static final void main() {
List exampleList = CollectionsKt.listOf(new Integer[]{1, 2, 3, 4, (Integer)null});
List mutableDestination = (List)(new ArrayList());
Iterable $this$mapNotNullTo$iv = (Iterable)exampleList;
int $i$f$mapNotNullTo = false;
int $i$f$forEach = false;
Iterator var6 = $this$mapNotNullTo$iv.iterator();
while(var6.hasNext()) {
public final class MainKt {
public static final void main() {
List exampleList = CollectionsKt.listOf(new Integer[]{1, 2, 3, 4, (Integer)null});
List mutableDestination = (List)(new ArrayList());
Iterator exampleListIterator = exampleList.iterator();
while(exampleListIterator.hasNext()) {
Integer exampleListElement = (Integer)exampleListIterator.next();
if (exampleListElement != null) {
int var4 = exampleListElement * 2;

Provides the reason as to why LocalContext.current as Activity is not suitable a suitable approach to get an Activity instance in Jetpack compose projects

The android system's view pipeline consists of two stages - measure and layout processes whereby the android framework measures the sizes of each view present in a view hierarchy (viewgroup) and proceeds to position them in specific positions on the screen. What this means is that the android framework only knows how to draw views on the android canvas.

Compose uses a similar logic to draw ui on its[compose] canvas. First, as you already know, Composes uses layout-nodes instead of views and for these nodes to be correctly positioned and drawn on the screen, it uses something called an applier(UiApplier).

As the name suggests the UiApplier transverses through the layout-nodes measuring and laying out (drawing) the nodes in specific positions on the Compose canvas. Think of compose system as a tree and the layout nodes as leaves.

Whatever is dra

package com.ciru.practice
import androidx.lifecycle.ViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.update
/**
package com.ciru.practice
import androidx.compose.runtime.Composable
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
/**
* Pass in an instance of [loginViewModel] and [navController]
* Reason why we are not instatiating/creating our viewmodel instance is here
package com.ciru.practice
import androidx.compose.runtime.Stable
/**
* I have annotated the class with [@Stable] marker to enforce equality contract needed
* by compose compiler. This is a bit advanced but when you do get time, do look at the jetpack compose compiler docs
* This class holds data needed by your composables, it is good practice to scope your data into a data class instead
* of using primitive types (string, char, etc) with StateFlow
*/
package com.ciru.practice
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.material.TextField