0%

JetpackCompose学习

1.介绍

2.编程思想

  • 可组合函数可以按任何顺序执行

  • 可组合函数可以并行运行

  • 重组会跳过尽可能多的内容

  • 重组是乐观的操作

    • 可组合项中的参数更改就会发生重组,重组过程中如果参数又发生改变,Compose会取消重组,并使用新的参数进行重组
    • side-effect 如果存在异步,则可能影响到重组
  • 可组合函数可能会非常频繁地运行

    3.状态

    3.1.可组合项中的状态

    1
    2
    3
    val mutableState = remember { mutableStateOf(default) }
    var value by remember { mutableStateOf(default) }
    val (value, setValue) = remember { mutableStateOf(default) }

    3.2其他受支持的状态类型

  • 其他类型需要先转化为有状态的State 才可以进行观察

  • 有状态和无状态,无状态便于测试,复用

    3.3状态提升

  • 状态提升很好的体现了Compose的数据从上到下,事件从下到上的思想

  • 类似于TextView setText和setOnClicklistener

    3.4在 Compose 中恢复状态

  • rememberSaveable 重启后可恢复状态

3.5在 Compose 中管理状态

  • 界面逻辑和界面元素状态
  • 状态容器(界面逻辑和界面元素状态的组合)
  • ViewModel

4.生命周期

  • 跳过状态未改变的组件
  • 列表中默认顺序不变,已有组件不会重组
  • 顺序改变时,使用key 来防止组件重组

5.Side Effect

  • LaunchedEffect : 当 LaunchedEffect 进入组合时,它会启动一个协程,并将代码块作为参数传递。如果 LaunchedEffect 退出组合,协程将取消。不同键的重组,将取消协程,并在新的协程中启用新的suspend 函数
  • rememberCoroutineScope:可组合项外启动协程
  • rememberUpdatedState:在效应中引用某个值,该效应在该值变化时不重启
  • DisposableEffect:需要清理的效应,注册和反注册功能
  • SideEffect:将 Compose 状态发布为非 Compose 代码
  • produceState:将非 Compose 状态转换为 Compose 状态
  • derivedStateOf:将一个或多个状态对象转换为其他状态
  • snapshotFlow:将 Compose 的 State 转换为 Flow

6.阶段

6.1组合

  • 状态值更改时,还进行重组,如果输入未发生改变,则会进行跳过

    6.2 布局

  • 测量

  • 放置

    6.3 绘制

  • 绘制阶段状态发生改变,只会影响绘制阶段

    7.架构分层

    全新的app 请基于Material 构建
    image.png

  • Runtime 提供了运行时的基本组件,状态容器相关。

  • 界面,界面相关,不包括基础组件

  • 基础 基础组件相关 在界之上的封装

  • Material 提供了 Material Design 主题,组件,指示器,图标等,相当于一套完善的工具包

ui中ui-tooling工具包需要单独依赖

依赖分析

material

1
2
3
4
5
6
7
8
9
10
11
+--- androidx.compose.material:material:1.1.1
| +--- androidx.compose.animation:animation-core:1.0.0 -> 1.1.1 (*)
| +--- androidx.compose.foundation:foundation:1.1.1 (*)
| +--- androidx.compose.material:material-icons-core:1.1.1
| | \--- androidx.compose.ui:ui:1.0.0 -> 1.1.1 (*)
| +--- androidx.compose.material:material-ripple:1.1.1
| | +--- androidx.compose.foundation:foundation:1.1.1 (*)
| | \--- androidx.compose.runtime:runtime:1.1.1 (*)
| +--- androidx.compose.runtime:runtime:1.1.1 (*)
| +--- androidx.compose.ui:ui:1.1.1 (*)
| \--- androidx.compose.ui:ui-text:1.0.0 -> 1.1.1 (*)

foundation

1
2
3
4
5
+--- androidx.compose.foundation:foundation:1.1.1
| +--- androidx.annotation:annotation:1.1.0 -> 1.2.0
| +--- androidx.compose.animation:animation:1.1.1
| +--- androidx.compose.runtime:runtime:1.1.1 (*)
| \--- androidx.compose.ui:ui:1.1.1 (*)

UI

1
2
3
4
5
6
7
8
+--- androidx.compose.ui:ui:1.1.1
| +--- androidx.compose.runtime:runtime-saveable:1.1.1
| +--- androidx.compose.ui:ui-geometry:1.1.1
| +--- androidx.compose.ui:ui-graphics:1.1.1
| +--- androidx.compose.ui:ui-text:1.1.1
| +--- androidx.compose.ui:ui-unit:1.1.1 (*)
| \--- androidx.annotation:annotation:1.1.0 -> 1.2.0
+--- androidx.compose.ui:ui-tooling:1.1.1

Runtime

1
+--- androidx.compose.runtime:runtime:1.1.1

代码

主要分析状态是怎么管理的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
@Composable
fun HelloContent() {
Column(modifier = Modifier.padding(16.dp)) {
var name by remember { mutableStateOf("") }
if (name.isNotEmpty()) {
Text(
text = "Hello, $name!",
modifier = Modifier.padding(bottom = 8.dp),
style = MaterialTheme.typography.h5
)
}
OutlinedTextField(
value = name,
onValueChange = { name = it },
label = { Text("Name") }
)
}
}

release

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package com.codelabs.state.todo;

/* compiled from: Test.kt */
@Metadata(d1 = {"\u0000\u0014\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0002\b\u0002\b\u0007\u0018\u00002\u00020\u0001B\u0005¢\u0006\u0002\u0010\u0002J\r\u0010\u0003\u001a\u00020\u0004H\u0007¢\u0006\u0002\u0010\u0005¨\u0006\u0006"}, d2 = {"Lcom/codelabs/state/todo/Test;", "", "()V", "HelloContent", "", "(Landroidx/compose/runtime/Composer;I)V", "finished_release"}, k = 1, mv = {1, 6, 0}, xi = 48)
public final class Test {
public static final int $stable = 0;

public final void HelloContent(Composer composer, int i) {
MutableState mutableState;
Composer startRestartGroup = composer.startRestartGroup(1502812017);
ComposerKt.sourceInformation(startRestartGroup, "C(HelloContent)");
if ((i & 1) != 0 || !startRestartGroup.getSkipping()) {
Modifier r2 = PaddingKt.m364padding3ABfNKs(Modifier.Companion, Dp.m3336constructorimpl((float) 16));
startRestartGroup.startReplaceableGroup(-1113030915);
ComposerKt.sourceInformation(startRestartGroup, "C(Column)P(2,3,1)76@3834L61,77@3900L133:Column.kt#2w3rfo");
boolean z = false;
MeasurePolicy columnMeasurePolicy = ColumnKt.columnMeasurePolicy(Arrangement.INSTANCE.getTop(), Alignment.Companion.getStart(), startRestartGroup, 0);
startRestartGroup.startReplaceableGroup(1376089394);
ComposerKt.sourceInformation(startRestartGroup, "C(Layout)P(!1,2)72@2847L7,73@2902L7,74@2961L7,75@2973L460:Layout.kt#80mrfh");
ComposerKt.sourceInformationMarkerStart(startRestartGroup, 103361330, "C:CompositionLocal.kt#9igjgp");
Object consume = startRestartGroup.consume(CompositionLocalsKt.getLocalDensity());
ComposerKt.sourceInformationMarkerEnd(startRestartGroup);
Density density = (Density) consume;
ComposerKt.sourceInformationMarkerStart(startRestartGroup, 103361330, "C:CompositionLocal.kt#9igjgp");
Object consume2 = startRestartGroup.consume(CompositionLocalsKt.getLocalLayoutDirection());
ComposerKt.sourceInformationMarkerEnd(startRestartGroup);
LayoutDirection layoutDirection = (LayoutDirection) consume2;
ComposerKt.sourceInformationMarkerStart(startRestartGroup, 103361330, "C:CompositionLocal.kt#9igjgp");
Object consume3 = startRestartGroup.consume(CompositionLocalsKt.getLocalViewConfiguration());
ComposerKt.sourceInformationMarkerEnd(startRestartGroup);
ViewConfiguration viewConfiguration = (ViewConfiguration) consume3;
Function0<ComposeUiNode> constructor = ComposeUiNode.Companion.getConstructor();
Function3<SkippableUpdater<ComposeUiNode>, Composer, Integer, Unit> materializerOf = LayoutKt.materializerOf(r2);
if (!(startRestartGroup.getApplier() instanceof Applier)) {
ComposablesKt.invalidApplier();
}
startRestartGroup.startReusableNode();
if (startRestartGroup.getInserting()) {
startRestartGroup.createNode(constructor);
} else {
startRestartGroup.useNode();
}
startRestartGroup.disableReusing();
Composer r7 = Updater.m1066constructorimpl(startRestartGroup);
Updater.m1073setimpl(r7, columnMeasurePolicy, ComposeUiNode.Companion.getSetMeasurePolicy());
Updater.m1073setimpl(r7, density, ComposeUiNode.Companion.getSetDensity());
Updater.m1073setimpl(r7, layoutDirection, ComposeUiNode.Companion.getSetLayoutDirection());
Updater.m1073setimpl(r7, viewConfiguration, ComposeUiNode.Companion.getSetViewConfiguration());
startRestartGroup.enableReusing();
materializerOf.invoke(SkippableUpdater.m1057boximpl(SkippableUpdater.m1058constructorimpl(startRestartGroup)), startRestartGroup, 0);
startRestartGroup.startReplaceableGroup(2058660585);
startRestartGroup.startReplaceableGroup(276693625);
ComposerKt.sourceInformation(startRestartGroup, "C78@3948L9:Column.kt#2w3rfo");
ColumnScopeInstance columnScopeInstance = ColumnScopeInstance.INSTANCE;
startRestartGroup.startReplaceableGroup(-3687241);
ComposerKt.sourceInformation(startRestartGroup, "C(remember):Composables.kt#9igjgp");
Object rememberedValue = startRestartGroup.rememberedValue();
if (rememberedValue == Composer.Companion.getEmpty()) {
rememberedValue = SnapshotStateKt__SnapshotStateKt.mutableStateOf$default("songpengfei", null, 2, null);
startRestartGroup.updateRememberedValue(rememberedValue);
}
startRestartGroup.endReplaceableGroup();
MutableState mutableState2 = (MutableState) rememberedValue;
startRestartGroup.startReplaceableGroup(690365227);
if (m3611HelloContent$lambda4$lambda1(mutableState2).length() > 0) {
z = true;
}
if (z) {
mutableState = mutableState2;
TextKt.m1027TextfLXpl1I("Hello, " + m3611HelloContent$lambda4$lambda1(mutableState2) + '!', PaddingKt.m368paddingqDBjuR0$default(Modifier.Companion, 0.0f, 0.0f, 0.0f, Dp.m3336constructorimpl((float) 8), 7, null), 0, 0, null, null, null, 0, null, null, 0, 0, false, 0, null, MaterialTheme.INSTANCE.getTypography(startRestartGroup, 8).getH5(), startRestartGroup, 48, 0, 32764);
} else {
mutableState = mutableState2;
}
startRestartGroup.endReplaceableGroup();
String r22 = m3611HelloContent$lambda4$lambda1(mutableState);
startRestartGroup.startReplaceableGroup(-3686930);
ComposerKt.sourceInformation(startRestartGroup, "C(remember)P(1):Composables.kt#9igjgp");
boolean changed = startRestartGroup.changed(mutableState);
Test$HelloContent$1$1$1 rememberedValue2 = startRestartGroup.rememberedValue();
if (changed || rememberedValue2 == Composer.Companion.getEmpty()) {
rememberedValue2 = new Function1<String, Unit>(mutableState) { // from class: com.codelabs.state.todo.Test$HelloContent$1$1$1
final /* synthetic */ MutableState<String> $name$delegate;

{
this.$name$delegate = r1;
}

/* Return type fixed from 'java.lang.Object' to match base method */
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
@Override // kotlin.jvm.functions.Function1
public /* bridge */ /* synthetic */ Unit invoke(String str) {
invoke(str);
return Unit.INSTANCE;
}

public final void invoke(String str) {
Intrinsics.checkNotNullParameter(str, "it");
Test.m3613access$HelloContent$lambda4$lambda2(this.$name$delegate, str);
}
};
startRestartGroup.updateRememberedValue(rememberedValue2);
}
startRestartGroup.endReplaceableGroup();
OutlinedTextFieldKt.OutlinedTextField(r22, (Function1<? super String, Unit>) ((Function1) rememberedValue2), (Modifier) null, false, false, (TextStyle) null, (Function2<? super Composer, ? super Integer, Unit>) ComposableSingletons$TestKt.INSTANCE.m3607getLambda1$finished_release(), (Function2<? super Composer, ? super Integer, Unit>) null, (Function2<? super Composer, ? super Integer, Unit>) null, (Function2<? super Composer, ? super Integer, Unit>) null, false, (VisualTransformation) null, (KeyboardOptions) null, (KeyboardActions) null, false, 0, (MutableInteractionSource) null, (Shape) null, (TextFieldColors) null, startRestartGroup, 1572864, 0, 524220);
startRestartGroup.endReplaceableGroup();
startRestartGroup.endReplaceableGroup();
startRestartGroup.endNode();
startRestartGroup.endReplaceableGroup();
startRestartGroup.endReplaceableGroup();
} else {
startRestartGroup.skipToGroupEnd();
}
ScopeUpdateScope endRestartGroup = startRestartGroup.endRestartGroup();
if (endRestartGroup != null) {
endRestartGroup.updateScope(new Function2<Composer, Integer, Unit>(this, i) { // from class: com.codelabs.state.todo.Test$HelloContent$2
final /* synthetic */ int $$changed;
final /* synthetic */ Test $tmp0_rcvr;

{
this.$tmp0_rcvr = r1;
this.$$changed = r2;
}

/* Return type fixed from 'java.lang.Object' to match base method */
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object, java.lang.Object] */
@Override // kotlin.jvm.functions.Function2
public /* bridge */ /* synthetic */ Unit invoke(Composer composer2, Integer num) {
invoke(composer2, num.intValue());
return Unit.INSTANCE;
}

public final void invoke(Composer composer2, int i2) {
this.$tmp0_rcvr.HelloContent(composer2, this.$$changed | 1);
}
});
}
}

/* renamed from: HelloContent$lambda-4$lambda-1 reason: not valid java name */
private static final String m3611HelloContent$lambda4$lambda1(MutableState<String> mutableState) {
return mutableState.getValue();
}

/* access modifiers changed from: private */
/* renamed from: HelloContent$lambda-4$lambda-2 reason: not valid java name */
public static final void m3612HelloContent$lambda4$lambda2(MutableState<String> mutableState, String str) {
mutableState.setValue(str);
}
}

debug

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155

/* compiled from: Test.kt */
@Metadata(d1 = {"\u0000\n\n\u0000\n\u0002\u0010\u0002\n\u0002\b\u0002\u001a\r\u0010\u0000\u001a\u00020\u0001H\u0007¢\u0006\u0002\u0010\u0002¨\u0006\u0003"}, d2 = {"HelloContent", "", "(Landroidx/compose/runtime/Composer;I)V", "finished_debug"}, k = 2, mv = {1, 6, 0}, xi = 48)
public final class TestKt {
public static final void HelloContent(Composer $composer, int $changed) {
Object value$iv$iv;
Composer $composer2 = $composer.startRestartGroup(-680870849);
ComposerKt.sourceInformation($composer2, "C(HelloContent)14@412L472:Test.kt#fhikc1");
if ($changed != 0 || !$composer2.getSkipping()) {
Modifier modifier$iv = PaddingKt.m364padding3ABfNKs(Modifier.Companion, Dp.m3355constructorimpl((float) LiveLiterals$TestKt.INSTANCE.m3646x53546f2d()));
$composer2.startReplaceableGroup(-1113030915);
ComposerKt.sourceInformation($composer2, "C(Column)P(2,3,1)76@3834L61,77@3900L133:Column.kt#2w3rfo");
MeasurePolicy measurePolicy$iv = ColumnKt.columnMeasurePolicy(Arrangement.INSTANCE.getTop(), Alignment.Companion.getStart(), $composer2, ((0 >> 3) & 14) | ((0 >> 3) & 112));
$composer2.startReplaceableGroup(1376089394);
ComposerKt.sourceInformation($composer2, "C(Layout)P(!1,2)72@2847L7,73@2902L7,74@2961L7,75@2973L460:Layout.kt#80mrfh");
ComposerKt.sourceInformationMarkerStart($composer2, 103361330, "C:CompositionLocal.kt#9igjgp");
Object consume = $composer2.consume(CompositionLocalsKt.getLocalDensity());
ComposerKt.sourceInformationMarkerEnd($composer2);
Density density$iv$iv = (Density) consume;
ComposerKt.sourceInformationMarkerStart($composer2, 103361330, "C:CompositionLocal.kt#9igjgp");
Object consume2 = $composer2.consume(CompositionLocalsKt.getLocalLayoutDirection());
ComposerKt.sourceInformationMarkerEnd($composer2);
LayoutDirection layoutDirection$iv$iv = (LayoutDirection) consume2;
ComposerKt.sourceInformationMarkerStart($composer2, 103361330, "C:CompositionLocal.kt#9igjgp");
Object consume3 = $composer2.consume(CompositionLocalsKt.getLocalViewConfiguration());
ComposerKt.sourceInformationMarkerEnd($composer2);
ViewConfiguration viewConfiguration$iv$iv = (ViewConfiguration) consume3;
Function0 factory$iv$iv$iv = ComposeUiNode.Companion.getConstructor();
Function3 skippableUpdate$iv$iv$iv = LayoutKt.materializerOf(modifier$iv);
int $changed$iv$iv$iv = ((((0 << 3) & 112) << 9) & 7168) | 6;
if (!($composer2.getApplier() instanceof Applier)) {
ComposablesKt.invalidApplier();
}
$composer2.startReusableNode();
if ($composer2.getInserting()) {
$composer2.createNode(factory$iv$iv$iv);
} else {
$composer2.useNode();
}
$composer2.disableReusing();
Composer $this$Layout_u24lambda_u2d0$iv$iv = Updater.m1066constructorimpl($composer2);
Updater.m1073setimpl($this$Layout_u24lambda_u2d0$iv$iv, measurePolicy$iv, ComposeUiNode.Companion.getSetMeasurePolicy());
Updater.m1073setimpl($this$Layout_u24lambda_u2d0$iv$iv, density$iv$iv, ComposeUiNode.Companion.getSetDensity());
Updater.m1073setimpl($this$Layout_u24lambda_u2d0$iv$iv, layoutDirection$iv$iv, ComposeUiNode.Companion.getSetLayoutDirection());
Updater.m1073setimpl($this$Layout_u24lambda_u2d0$iv$iv, viewConfiguration$iv$iv, ComposeUiNode.Companion.getSetViewConfiguration());
$composer2.enableReusing();
skippableUpdate$iv$iv$iv.invoke(SkippableUpdater.m1057boximpl(SkippableUpdater.m1058constructorimpl($composer2)), $composer2, Integer.valueOf(($changed$iv$iv$iv >> 3) & 112));
$composer2.startReplaceableGroup(2058660585);
$composer2.startReplaceableGroup(276693625);
ComposerKt.sourceInformation($composer2, "C78@3948L9:Column.kt#2w3rfo");
if ((((($changed$iv$iv$iv >> 9) & 14) & 11) ^ 2) != 0 || !$composer2.getSkipping()) {
ColumnScopeInstance columnScopeInstance = ColumnScopeInstance.INSTANCE;
$composer2.startReplaceableGroup(475235502);
ComposerKt.sourceInformation($composer2, "C15@477L31,25@817L13,23@744L134:Test.kt#fhikc1");
if ((((((0 >> 6) & 112) | 6) & 81) ^ 16) != 0 || !$composer2.getSkipping()) {
$composer2.startReplaceableGroup(-3687241);
ComposerKt.sourceInformation($composer2, "C(remember):Composables.kt#9igjgp");
Object value$iv$iv2 = $composer2.rememberedValue();
if (value$iv$iv2 == Composer.Companion.getEmpty()) {
value$iv$iv2 = SnapshotStateKt__SnapshotStateKt.mutableStateOf$default(LiveLiterals$TestKt.INSTANCE.m3651x68b1e380(), null, 2, null);
$composer2.updateRememberedValue(value$iv$iv2);
}
$composer2.endReplaceableGroup();
MutableState name$delegate = (MutableState) value$iv$iv2;
$composer2.startReplaceableGroup(475235554);
ComposerKt.sourceInformation($composer2, "20@698L10,17@554L171");
if (m3704HelloContent$lambda4$lambda1(name$delegate).length() > 0) {
TextKt.m1027TextfLXpl1I(LiveLiterals$TestKt.INSTANCE.m3648xc357f905() + m3704HelloContent$lambda4$lambda1(name$delegate) + LiveLiterals$TestKt.INSTANCE.m3649x20bacd43(), PaddingKt.m368paddingqDBjuR0$default(Modifier.Companion, 0.0f, 0.0f, 0.0f, Dp.m3355constructorimpl((float) LiveLiterals$TestKt.INSTANCE.m3647x7cb49cbb()), 7, null), 0, 0, null, null, null, 0, null, null, 0, 0, false, 0, null, MaterialTheme.INSTANCE.getTypography($composer2, 8).getH5(), $composer2, 0, 0, 32764);
}
$composer2.endReplaceableGroup();
String r23 = m3704HelloContent$lambda4$lambda1(name$delegate);
$composer2.startReplaceableGroup(-3686930);
ComposerKt.sourceInformation($composer2, "C(remember)P(1):Composables.kt#9igjgp");
boolean invalid$iv$iv = $composer2.changed(name$delegate);
Object it$iv$iv = $composer2.rememberedValue();
if (!invalid$iv$iv) {
if (it$iv$iv != Composer.Companion.getEmpty()) {
value$iv$iv = it$iv$iv;
$composer2.endReplaceableGroup();
OutlinedTextFieldKt.OutlinedTextField(r23, (Function1<? super String, Unit>) ((Function1) value$iv$iv), (Modifier) null, false, false, (TextStyle) null, (Function2<? super Composer, ? super Integer, Unit>) ComposableSingletons$TestKt.INSTANCE.m3626getLambda1$finished_debug(), (Function2<? super Composer, ? super Integer, Unit>) null, (Function2<? super Composer, ? super Integer, Unit>) null, (Function2<? super Composer, ? super Integer, Unit>) null, false, (VisualTransformation) null, (KeyboardOptions) null, (KeyboardActions) null, false, 0, (MutableInteractionSource) null, (Shape) null, (TextFieldColors) null, $composer2, 1572864, 0, 524220);
}
}
value$iv$iv = (Function1) new Function1<String, Unit>(name$delegate) { // from class: com.codelabs.state.todo.TestKt$HelloContent$1$1$1
final /* synthetic */ MutableState<String> $name$delegate;

{
this.$name$delegate = r2;
}

/* Return type fixed from 'java.lang.Object' to match base method */
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
@Override // kotlin.jvm.functions.Function1
public /* bridge */ /* synthetic */ Unit invoke(String str) {
invoke(str);
return Unit.INSTANCE;
}

public final void invoke(String it) {
Intrinsics.checkNotNullParameter(it, "it");
TestKt.m3706access$HelloContent$lambda4$lambda2(this.$name$delegate, it);
}
};
$composer2.updateRememberedValue(value$iv$iv);
$composer2.endReplaceableGroup();
OutlinedTextFieldKt.OutlinedTextField(r23, (Function1<? super String, Unit>) ((Function1) value$iv$iv), (Modifier) null, false, false, (TextStyle) null, (Function2<? super Composer, ? super Integer, Unit>) ComposableSingletons$TestKt.INSTANCE.m3626getLambda1$finished_debug(), (Function2<? super Composer, ? super Integer, Unit>) null, (Function2<? super Composer, ? super Integer, Unit>) null, (Function2<? super Composer, ? super Integer, Unit>) null, false, (VisualTransformation) null, (KeyboardOptions) null, (KeyboardActions) null, false, 0, (MutableInteractionSource) null, (Shape) null, (TextFieldColors) null, $composer2, 1572864, 0, 524220);
} else {
$composer2.skipToGroupEnd();
}
$composer2.endReplaceableGroup();
} else {
$composer2.skipToGroupEnd();
}
$composer2.endReplaceableGroup();
$composer2.endReplaceableGroup();
$composer2.endNode();
$composer2.endReplaceableGroup();
$composer2.endReplaceableGroup();
} else {
$composer2.skipToGroupEnd();
}
ScopeUpdateScope endRestartGroup = $composer2.endRestartGroup();
if (endRestartGroup != null) {
endRestartGroup.updateScope(new Function2<Composer, Integer, Unit>($changed) { // from class: com.codelabs.state.todo.TestKt$HelloContent$2
final /* synthetic */ int $$changed;

{
this.$$changed = r2;
}

/* Return type fixed from 'java.lang.Object' to match base method */
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object, java.lang.Object] */
@Override // kotlin.jvm.functions.Function2
public /* bridge */ /* synthetic */ Unit invoke(Composer composer, Integer num) {
invoke(composer, num.intValue());
return Unit.INSTANCE;
}

public final void invoke(Composer composer, int i) {
TestKt.HelloContent(composer, this.$$changed | 1);
}
});
}
}

/* renamed from: HelloContent$lambda-4$lambda-1 reason: not valid java name */
private static final String m3704HelloContent$lambda4$lambda1(MutableState<String> $this$getValue$iv) {
return $this$getValue$iv.getValue();
}

/* access modifiers changed from: private */
/* renamed from: HelloContent$lambda-4$lambda-2 reason: not valid java name */
public static final void m3705HelloContent$lambda4$lambda2(MutableState<String> mutableState, String value) {
mutableState.setValue(value);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
@Composable
fun HelloContent() {
Column(modifier = Modifier.padding(16.dp)) {
var name = "songpengfei"
Text(
text = "Hello, $name!",
modifier = Modifier.padding(bottom = 8.dp),
style = MaterialTheme.typography.h5
)

OutlinedTextField(
value = name,
onValueChange = { name = it },
label = { Text("Name") }
)
}
}

没有状态时

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package com.codelabs.state.todo;

/* compiled from: Test.kt */
@Metadata(d1 = {"\u0000\n\n\u0000\n\u0002\u0010\u0002\n\u0002\b\u0002\u001a\r\u0010\u0000\u001a\u00020\u0001H\u0007¢\u0006\u0002\u0010\u0002¨\u0006\u0003"}, d2 = {"HelloContent", "", "(Landroidx/compose/runtime/Composer;I)V", "finished_debug"}, k = 2, mv = {1, 6, 0}, xi = 48)
public final class TestKt {
public static final void HelloContent(Composer $composer, int $changed) {
Composer $composer2 = $composer.startRestartGroup(-680870849);
ComposerKt.sourceInformation($composer2, "C(HelloContent)14@412L391:Test.kt#fhikc1");
if ($changed != 0 || !$composer2.getSkipping()) {
Modifier modifier$iv = PaddingKt.m364padding3ABfNKs(Modifier.Companion, Dp.m3355constructorimpl((float) LiveLiterals$TestKt.INSTANCE.m3646x53546f2d()));
$composer2.startReplaceableGroup(-1113030915);
ComposerKt.sourceInformation($composer2, "C(Column)P(2,3,1)76@3834L61,77@3900L133:Column.kt#2w3rfo");
MeasurePolicy measurePolicy$iv = ColumnKt.columnMeasurePolicy(Arrangement.INSTANCE.getTop(), Alignment.Companion.getStart(), $composer2, ((0 >> 3) & 14) | ((0 >> 3) & 112));
$composer2.startReplaceableGroup(1376089394);
ComposerKt.sourceInformation($composer2, "C(Layout)P(!1,2)72@2847L7,73@2902L7,74@2961L7,75@2973L460:Layout.kt#80mrfh");
ComposerKt.sourceInformationMarkerStart($composer2, 103361330, "C:CompositionLocal.kt#9igjgp");
Object consume = $composer2.consume(CompositionLocalsKt.getLocalDensity());
ComposerKt.sourceInformationMarkerEnd($composer2);
Density density$iv$iv = (Density) consume;
ComposerKt.sourceInformationMarkerStart($composer2, 103361330, "C:CompositionLocal.kt#9igjgp");
Object consume2 = $composer2.consume(CompositionLocalsKt.getLocalLayoutDirection());
ComposerKt.sourceInformationMarkerEnd($composer2);
LayoutDirection layoutDirection$iv$iv = (LayoutDirection) consume2;
ComposerKt.sourceInformationMarkerStart($composer2, 103361330, "C:CompositionLocal.kt#9igjgp");
Object consume3 = $composer2.consume(CompositionLocalsKt.getLocalViewConfiguration());
ComposerKt.sourceInformationMarkerEnd($composer2);
ViewConfiguration viewConfiguration$iv$iv = (ViewConfiguration) consume3;
Function0 factory$iv$iv$iv = ComposeUiNode.Companion.getConstructor();
Function3 skippableUpdate$iv$iv$iv = LayoutKt.materializerOf(modifier$iv);
int $changed$iv$iv$iv = ((((0 << 3) & 112) << 9) & 7168) | 6;
if (!($composer2.getApplier() instanceof Applier)) {
ComposablesKt.invalidApplier();
}
$composer2.startReusableNode();
if ($composer2.getInserting()) {
$composer2.createNode(factory$iv$iv$iv);
} else {
$composer2.useNode();
}
$composer2.disableReusing();
Composer $this$Layout_u24lambda_u2d0$iv$iv = Updater.m1066constructorimpl($composer2);
Updater.m1073setimpl($this$Layout_u24lambda_u2d0$iv$iv, measurePolicy$iv, ComposeUiNode.Companion.getSetMeasurePolicy());
Updater.m1073setimpl($this$Layout_u24lambda_u2d0$iv$iv, density$iv$iv, ComposeUiNode.Companion.getSetDensity());
Updater.m1073setimpl($this$Layout_u24lambda_u2d0$iv$iv, layoutDirection$iv$iv, ComposeUiNode.Companion.getSetLayoutDirection());
Updater.m1073setimpl($this$Layout_u24lambda_u2d0$iv$iv, viewConfiguration$iv$iv, ComposeUiNode.Companion.getSetViewConfiguration());
$composer2.enableReusing();
skippableUpdate$iv$iv$iv.invoke(SkippableUpdater.m1057boximpl(SkippableUpdater.m1058constructorimpl($composer2)), $composer2, Integer.valueOf(($changed$iv$iv$iv >> 3) & 112));
$composer2.startReplaceableGroup(2058660585);
$composer2.startReplaceableGroup(276693625);
ComposerKt.sourceInformation($composer2, "C78@3948L9:Column.kt#2w3rfo");
if ((((($changed$iv$iv$iv >> 9) & 14) & 11) ^ 2) != 0 || !$composer2.getSkipping()) {
ColumnScopeInstance columnScopeInstance = ColumnScopeInstance.INSTANCE;
$composer2.startReplaceableGroup(475235502);
ComposerKt.sourceInformation($composer2, "C19@630L10,16@498L155,22@663L134:Test.kt#fhikc1");
if ((((((0 >> 6) & 112) | 6) & 81) ^ 16) != 0 || !$composer2.getSkipping()) {
Ref.ObjectRef name = new Ref.ObjectRef();
name.element = (T) LiveLiterals$TestKt.INSTANCE.m3651x6aed80d();
TextKt.m1027TextfLXpl1I(LiveLiterals$TestKt.INSTANCE.m3648xedbb17e0() + ((String) name.element) + LiveLiterals$TestKt.INSTANCE.m3649xf250819e(), PaddingKt.m368paddingqDBjuR0$default(Modifier.Companion, 0.0f, 0.0f, 0.0f, Dp.m3355constructorimpl((float) LiveLiterals$TestKt.INSTANCE.m3647x3ce8c716()), 7, null), 0, 0, null, null, null, 0, null, null, 0, 0, false, 0, null, MaterialTheme.INSTANCE.getTypography($composer2, 8).getH5(), $composer2, 0, 0, 32764);
OutlinedTextFieldKt.OutlinedTextField((String) name.element, (Function1<? super String, Unit>) new Function1<String, Unit>(name) { // from class: com.codelabs.state.todo.TestKt$HelloContent$1$1
final /* synthetic */ Ref.ObjectRef<String> $name;

{
this.$name = r2;
}

/* Return type fixed from 'java.lang.Object' to match base method */
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
@Override // kotlin.jvm.functions.Function1
public /* bridge */ /* synthetic */ Unit invoke(String str) {
invoke(str);
return Unit.INSTANCE;
}

/* JADX DEBUG: Multi-variable search result rejected for r2v0, resolved type: java.lang.String */
/* JADX WARN: Multi-variable type inference failed */
public final void invoke(String it) {
Intrinsics.checkNotNullParameter(it, "it");
this.$name.element = it;
}
}, (Modifier) null, false, false, (TextStyle) null, (Function2<? super Composer, ? super Integer, Unit>) ComposableSingletons$TestKt.INSTANCE.m3626getLambda1$finished_debug(), (Function2<? super Composer, ? super Integer, Unit>) null, (Function2<? super Composer, ? super Integer, Unit>) null, (Function2<? super Composer, ? super Integer, Unit>) null, false, (VisualTransformation) null, (KeyboardOptions) null, (KeyboardActions) null, false, 0, (MutableInteractionSource) null, (Shape) null, (TextFieldColors) null, $composer2, 1572864, 0, 524220);
} else {
$composer2.skipToGroupEnd();
}
$composer2.endReplaceableGroup();
} else {
$composer2.skipToGroupEnd();
}
$composer2.endReplaceableGroup();
$composer2.endReplaceableGroup();
$composer2.endNode();
$composer2.endReplaceableGroup();
$composer2.endReplaceableGroup();
} else {
$composer2.skipToGroupEnd();
}
ScopeUpdateScope endRestartGroup = $composer2.endRestartGroup();
if (endRestartGroup != null) {
endRestartGroup.updateScope(new Function2<Composer, Integer, Unit>($changed) { // from class: com.codelabs.state.todo.TestKt$HelloContent$2
final /* synthetic */ int $$changed;

{
this.$$changed = r2;
}

/* Return type fixed from 'java.lang.Object' to match base method */
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object, java.lang.Object] */
@Override // kotlin.jvm.functions.Function2
public /* bridge */ /* synthetic */ Unit invoke(Composer composer, Integer num) {
invoke(composer, num.intValue());
return Unit.INSTANCE;
}

public final void invoke(Composer composer, int i) {
TestKt.HelloContent(composer, this.$$changed | 1);
}
});
}
}
}