Separating Program Evaluation From Description

Stream, Lazy, Map, Filter, EVAL

Guowei Lv

4 minute read

5.3 Separating program evaluation from description This is the title of Chapter 5.3 from the book Functional Programming in Kotlin. Everyone knows that a program is a list of instructions that will be executed/evaluated in the order they are written in. fun exec() { doThis() doThat() doMore() } So the description decides the evaluation. What does it mean to separate them? I mean, can they be different?

Handmade NestedScrollView

Understand how nested scrolling works in Android

Guowei Lv

3 minute read

I’m learning how the nested scrolling machanism works on Android, but couldn’t really find any in-depth material. So I turned into the Chinese community, and found this incredible article. It is very long and detailed to death, I don’t really have time to go through it all. I find the first half, a handmade SimpleNestedScrollView to be quite interesting, let me put that part in English here. Understand the problem If you have a ScrollView inside another ScrollView(same scrolling direction, both vertical or horizontal), then what to expect of the scrolling behaviour?

Understand Android View's Touch Events

How touch events are handled

Guowei Lv

7 minute read

How the view system in Android handles touch events? Let’s try to understand it by designing it from scratch ourselves! (This is not my original but a summary of this https://juejin.cn/post/6844903761052188679) Let’s do this by coming up a series of requirements (from naive to sophisticated) and see how we can design the logic to fulfill them. Requirement 1 In a nested view hierachy, only the most inner view can handle events.

WTF Livedata?! (or Kotlin)

Some unexpected behavior of LiveData(Kotlin really)

Guowei Lv

3 minute read

LiveData is convenient, powerful and super easy to use. But, there are still some quirks that could possibly leads to some heads banging against walls. How many times can I observe? In theory, we can observe livedata with multiple observers, just like the good old pub-sub pattern, right? Well, let’s test this out. Let’s create a super simple livedata. class MainViewModel : ViewModel() { private val _data = MutableLiveData<Int>() val data: LiveData<Int> = _data fun update(count: Int) { _data.

Fun Facts About OnMeasure() and OnLayout()

Help you understander better about measure and layout

Guowei Lv

2 minute read

Let’s understand more about Android view’s measure and layout process, and have some fun along the way. Let’s say we have this: <LinearLayout 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"> <com.example.stubornview.StubbornView android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/design_default_color_primary" /> </LinearLayout> class StubbornView @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 ) : View(context, attrs, defStyleAttr) { /** * 1. Parent LinearLayout combines developer's requirements * and the available space of itself into MeasureSpecs and * pass them here.