Share
Embed
Jetpack Compose A to Z (full)
Jetpack Compose A to Z 리허설 전 full 자료 (70분)
Ji Sungbin
February 23, 2023
Transcript
174 slides
-
$PMVNO3PX🙅 #PY#PY8JUI$POTUSBJOUT🙅 -B[Z-JTU🙅 $POTUSBJOU-BZPVU🙅 -BZPVU🙅
-PPLBIFBE-BZPVU🥳 BOJNBUJPOGSBNFਸ୶ೞӝਤೠۨইਓ -
start fi nish 1st intermediate layout 2nd intermediate layout 3rd
intermediate layout Lookahead 1. Modi fi er.onPlaced 2. Modi fi er.intermediateLayout -
/** * ۨইਓਸ Ѿೞӝ ਤ೧ measure ܳ ܻ ೞҊ ୶റ
placement ױ҅ܳ प೯ೞח ۨইਓੑפ. => measure ܳ ܻ ೞח ױ҅: lookahead ױ҅ * lookahead ױ҅о աݶ ୶റ [LookaheadLayoutScope.intermediateLayout] ਸ ా೧ * lookahead Ѿҗܳ ӝ߈ਵ۽ ۨইਓ measure ߂ placement ܳ ઑೡ ࣻ ח ژ ܲ measure ߂ placement ױ҅о दؾפ. => intermediate layout * * ܳ ਊೞৈ ۨইਓ ܻ measure ػ intermediate layout ਸ ೱ೧ ӝ৬ ਤܳ ରਵ۽ ߸҃ೡ ࣻ णפ. */ @ExperimentalComposeUiApi @UiComposable @Composable fun LookaheadLayout( content: @Composable @UiComposable LookaheadLayoutScope.() -> Unit, modifier: Modifier = Modifier, measurePolicy: MeasurePolicy ) -
/** * [LookaheadLayout] ݽٚ( ߂ р) ೞਤ ۨইਓী ೠ
receiver ߧਤܳ ઁҕפ. * lookahead ױ҅ীࢲ ҅ػ ۨইਓ measurement ߂ placement ח * [LookaheadLayoutScope] ীࢲ пп [Modifier.intermediateLayout] ߂ [Modifier.onPlaced] ܳ ా೧ observe ೡ ࣻ णפ. */ @ExperimentalComposeUiApi interface LookaheadLayoutScope { fun Modifier.onPlaced( onPlaced: ( lookaheadScopeCoordinates: LookaheadLayoutCoordinates, layoutCoordinates: LookaheadLayoutCoordinates ) -> Unit ): Modifier fun Modifier.intermediateLayout( measure: MeasureScope.( measurable: Measurable, constraints: Constraints, lookaheadSize: IntSize ) -> MeasureResult ): Modifier } -
@ExperimentalComposeUiApi interface LookaheadLayoutScope { /** * intermediate layout ߓؼ
ਤо ҅ػ റ ഐؾפ. * * [LookaheadLayoutCoordinates] о যݶ ҅ػ intermediate layout য়ࣇҗ അ ߓظ ח ஹನ࠶ য়ࣇਸ * [LookaheadLayoutCoordinates.localLookaheadPositionOf] ৬ [LookaheadLayoutCoordinates.localPositionOf] ܳ ࢎਊೞৈ ਸ ࣻ णפ. * ܳ ా೧ ҅ػ intermediate layout য়ࣇਸ ӝ߈ਵ۽ ஹನ࠶ ߓܳ ઑೡ ࣻ णפ. * * [onPlaced ۈ ੋ] * * @param lookaheadScopeCoordinates [LookaheadLayout] ࢎਊೞח [LookaheadLayoutCoordinates] * @param layoutCoordinates modifier ஹನ࠶ ࢎਊೞח [LookaheadLayoutCoordinates] */ fun Modifier.onPlaced( onPlaced: ( lookaheadScopeCoordinates: LookaheadLayoutCoordinates, layoutCoordinates: LookaheadLayoutCoordinates ) -> Unit ): Modifier fun Modifier.intermediateLayout( measure: MeasureScope.( measurable: Measurable, constraints: Constraints, lookaheadSize: IntSize -
start fi nish Lookahead 1st intermediate layout 2nd intermediate layout
will be 3rd intermediate layout OEJOUFSNFEJBUFMBZPVUীࢲप೯غח࢚ട JOUFSNFEJBUFMBZPVUߓؼਤܳ҅ೣ റ೧ਤܳModifier.onPlaced۽ࠁն -
@ExperimentalComposeUiApi interface LookaheadLayoutScope { /** * intermediate layout ߓؼ
ਤо ҅ػ റ ഐؾפ. * * [LookaheadLayoutCoordinates] о যݶ ҅ػ intermediate layout য়ࣇҗ അ ߓظ ח ஹನ࠶ য়ࣇਸ * [LookaheadLayoutCoordinates.localLookaheadPositionOf] ৬ [LookaheadLayoutCoordinates.localPositionOf] ܳ ࢎਊೞৈ ਸ ࣻ णפ. * ܳ ా೧ ҅ػ intermediate layout য়ࣇਸ ӝ߈ਵ۽ ஹನ࠶ ߓܳ ઑೡ ࣻ णפ. * * [onPlaced ۈ ੋ] * * @param lookaheadScopeCoordinates [LookaheadLayout] ࢎਊೞח [LookaheadLayoutCoordinates] * @param layoutCoordinates modifier ஹನ࠶ ࢎਊೞח [LookaheadLayoutCoordinates] */ fun Modifier.onPlaced( onPlaced: ( lookaheadScopeCoordinates: LookaheadLayoutCoordinates, layoutCoordinates: LookaheadLayoutCoordinates ) -> Unit ): Modifier fun Modifier.intermediateLayout( measure: MeasureScope.( measurable: Measurable, constraints: Constraints, lookaheadSize: IntSize -
/** * ۨইਓী ೧ measure ػ bounds ഓ؊ੑפ. */
@JvmDefaultWithCompatibility interface LayoutCoordinates { // … ࢤۚ /** * [sourceCoordinates] ҕр [relativeToSource] ܳ ۽ஸ coordinate ۽ ߸ജפ. * [sourceCoordinates] ח زੌೠ ۨইਓ ҅கী ࣘೞח ݽٚ [LayoutCoordinates] ੌ ࣻ णפ. * * @param sourceCoordinates ߸ജೡ [Offset] ח [LayoutCoordinates] * @param relativeToSource ߸ഝೡ [Offset] * * @return ۽ஸ coordinate ۽ ߸ജػ [Offset] */ fun localPositionOf(sourceCoordinates: LayoutCoordinates, relativeToSource: Offset): Offset } -
/** * lookhead ױ҅ ೯ җ റ ۨইਓ ݽف [LayoutCoordinates]
ܳ ࠁਬפ. */ @ExperimentalComposeUiApi sealed interface LookaheadLayoutCoordinates : LayoutCoordinates { /** * [sourceCoordinates] ҕр [relativeToSource] ܳ ۽ஸ coordinate ۽ ߸ജפ. * [sourceCoordinates] ח زੌೠ ۨইਓ ҅கী ࣘೞח ݽٚ [LookaheadLayoutCoordinates] ੌ ࣻ णפ. * * [localPositionOf] ৬ ׳ܻ [localLookaheadPositionOf] ח coordinate ҅ਸ ਤ೧ lookahead ਤܳ ࢎਊפ. * * @param sourceCoordinates ߸ജೡ [Offset] ח [LookaheadLayoutCoordinates] * @param relativeToSource ߸ഝೡ [Offset] * * @return ۽ஸ coordinate ۽ ߸ജػ [Offset] */ fun localLookaheadPositionOf( sourceCoordinates: LookaheadLayoutCoordinates, relativeToSource: Offset = Offset.Zero ): Offset } -
// interface LookaheadLayoutScope /** * lookahead ױ҅ীࢲ ҅ػ ࠁܳ ӝ߈ਵ۽
intermediate layout ܳ ߓפ. * intermediate layout ӝо ઁҕغח ۈੋ [measure] ੋܳ ా೧ intermediate layout ܳ morph ೡ ࣻ णפ. * * morph: അ ݽনਸ ܲ ݽনਵ۽ ߄Բח Ѫ * * [measure ۈ ੋ] * * @param measurable intermediate layout measurable * @param constraints intermediate layout constraints * @param lookaheadSize intermediate layout ӝ */ fun Modifier.intermediateLayout( measure: MeasureScope.( measurable: Measurable, constraints: Constraints, lookaheadSize: IntSize ) -> MeasureResult ): Modifier } -
start fi nish Lookahead 1st intermediate layout 2nd intermediate layout
will be 3rd intermediate layout OEJOUFSNFEJBUFMBZPVUীࢲप೯غח࢚ട Modifier.intermediateLayoutਵ۽ߓೡҔ LookaheadLayoutCoordinates.localLookaheadPositionOfয়ࣇ LookaheadLayoutCoordinates.localPositionOfয়ࣇ -
ӝઑ.PEJGJFSJNUFSNFEJBUF-BZPVU /** * lookahead ױ҅ীࢲ ҅ػ ࠁܳ ӝ߈ਵ۽ intermediate layout
ܳ ߓפ. * intermediate layout ӝо ઁҕغח ۈੋ [measure] ੋܳ ా೧ intermediate layout ܳ morph ೡ ࣻ णפ. */ fun Modifier.intermediateLayout( measure: MeasureScope.( measurable: Measurable, constraints: Constraints, lookaheadSize: IntSize ) -> MeasureResult ): Modifier -
য়ࣇઑ.PEJGJFSPO1MBDFE /** * [LookaheadLayoutCoordinates] о যݶ ҅ػ intermediate layout
য়ࣇҗ അ ߓظ ח ஹನ࠶ য়ࣇਸ * [LookaheadLayoutCoordinates.localLookaheadPositionOf] ৬ [LookaheadLayoutCoordinates.localPositionOf] ܳ ࢎਊೞৈ ਸ ࣻ णפ. * ܳ ా೧ ҅ػ intermediate layout য়ࣇਸ ӝ߈ਵ۽ ஹನ࠶ ߓܳ ઑೡ ࣻ णפ. */ fun Modifier.onPlaced( onPlaced: ( lookaheadScopeCoordinates: LookaheadLayoutCoordinates, layoutCoordinates: LookaheadLayoutCoordinates ) -> Unit ): Modifier -
fun Modifier.movement(lookaheadScope: LookaheadLayoutScope) = composed { var targetOffset: IntOffset? by
remember { mutableStateOf(null) } // ߓೡ য়ࣇ var placementOffset by remember { mutableStateOf(IntOffset.Zero) } // അ য়ࣇ with(lookaheadScope) { this@composed .onPlaced { lookaheadScopeCoordinates, layoutCoordinates -> // LookaheadLayout ۽ஸ coordinates ীࢲ modifier lookahead ਤܳ ߈ജ targetOffset = lookaheadScopeCoordinates .localLookaheadPositionOf(sourceCoordinates = layoutCoordinates) .round() // о оө IntOffset чਵ۽ য়ࣇ ߈ৢܿ // LookaheadLayout ۽ஸ coordinates ীࢲ modifier അ ਤܳ ߈ജ placementOffset = lookaheadScopeCoordinates .localPositionOf( sourceCoordinates = layoutCoordinates, relativeToSource = Offset.Zero ) .round() } .intermediateLayout { measurable, constraints, _ -> val placeable = measurable.measure(constraints) layout(width = placeable.width, height = placeable.height) { // زೠ য়ࣇী ߓ -
targetOffset = lookaheadScopeCoordinates .localLookaheadPositionOf(sourceCoordinates = layoutCoordinates) .round() // о оө
IntOffset чਵ۽ য়ࣇ ߈ৢܿ // LookaheadLayout ۽ஸ coordinate ীࢲ modifier അ ਤܳ ߈ജ placementOffset = lookaheadScopeCoordinates .localPositionOf( sourceCoordinates = layoutCoordinates, relativeToSource = Offset.Zero ) .round() } .intermediateLayout { measurable, constraints, _ -> val placeable = measurable.measure(constraints) layout(width = placeable.width, height = placeable.height) { // زೠ য়ࣇী ߓ val (x, y) = targetOffset!! - placementOffset placeable.place(x = x, y = y) } } } } -
fun Modifier.transformation(lookaheadScope: LookaheadLayoutScope) = with(lookaheadScope) { intermediateLayout { measurable, _,
lookaheadSize -> val (width, height) = lookaheadSize // lookahead ӝ۽ width, height Ѿ val animatedConstraints = Constraints.fixed( width = width.coerceAtLeast(0), // ୭ࣗ 0 ਵ۽ ࢸ height = height.coerceAtLeast(0) ) val placeable = measurable.measure(animatedConstraints) layout(width = placeable.width, height = placeable.height) { // lookahead ӝী ݏѱ ߓ placeable.place(x = 0, y = 0) } } } -
LookaheadLayout( modifier = modifier .fillMaxSize() .navigationBarsPadding() .padding(16.dp), content = {
Fab( modifier = Modifier .size( size = FabDefaults.size( isExpanded = isExpanded, maxWidthDp = screenMaxWidth.dp ) ) .movement(lookaheadScope = this) .transformation(lookaheadScope = this) .noRippleClickable { isExpanded = !isExpanded }, isExpanded = isExpanded ) }, measurePolicy = DefaultMeasurePolicy ) -
ఫझ࢚࢝গפݫ࣌➡️BOJNBUF$PMPS"T4UBUF ߣبزੌ ߓ҃ਤزগפݫ࣌➡️ߓ࢚҃࢝গפݫ࣌ਵ۽द GBEFJOPVU➡️"OJNBUFE$POUFOU TMJEFJOPVU
GBEFJOPVU➡️"OJNBUFE$POUFOU "GUFS🪄 -
Column( modifier = Modifier.fillMaxSize().background(color = Color.BackgroundWhite), verticalArrangement = Arrangement.SpaceBetween )
{ TabContainer { TabDefaults.Items.forEach { tab -> TabItem( title = tab.shortname, backgroundColor = tabBackgroundColor(selectedTab = selectedTabState, nowTab = tab), textColor = tabTextColor(selectedTab = selectedTabState, nowTab = tab), onTabClick = { selectedTabState = tab } ) } } MovieContainer { MovieName(fullname = selectedTabState.fullname) MoviePoster(posterDrawable = selectedTabState.poster) } } -
@Stable private fun tabBackgroundColor( selectedTab: Int, nowTab: Int ): Color
= when (selectedTab == nowTab) { true -> TabDefaults.Color.selectedBackground false -> TabDefaults.Color.defaultBackground } @Stable private fun tabTextColor( selectedTab: Int, nowTab: Int ): Color = when (selectedTab == nowTab) { true -> TabDefaults.Color.selectedText false -> TabDefaults.Color.defaultText } @Composable private fun tabBackgroundColorWithAnimation( selectedTab: Tab, nowTab: Tab ): Color = animateColorAsState( targetValue = when (selectedTab == nowTab) { true -> TabDefaults.Color.selectedBackground false -> TabDefaults.Color.defaultBackground } ).value @Composable private fun tabTextColorWithAnimation( selectedTab: Tab, nowTab: Tab ): Color = animateColorAsState( targetValue = when (selectedTab == nowTab) { true -> TabDefaults.Color.selectedText false -> TabDefaults.Color.defaultText } ).value -
/** * [Color] ী ೠ Fire-and-Forget গפݫ࣌ ӝמਸ ઁҕפ. *
animate*AsState ח [Float], [Color], [Dp], [Size], [Offset], [Rect], [Int], [IntOffset] ӒܻҊ [IntSize] ী ࢎ ظ णפ. * ઁҕػ [targetValue] о ߸҃غݶ গפݫ࣌ زਵ۽ प೯ؾפ. * [targetValue] о ߸҃ؼ ٸ ೯ ੋ গפݫ࣌ ח ҃ ೯ ੋ গפݫ࣌ ࢜۽ [targetValue] ܳ ೱ೧ গפݫ࣌غب۾ झܳ ઑפ. * * animate*AsState ח গפݫ࣌ ਊغҊ ח [State] ܳ ߈ജפ. * * @param targetValue গפݫ࣌ ఋѶ * @param animationSpec दрী ٮۄ чਸ ߸҃ೞח ؘ ࢎਊೡ গפݫ࣌ * @param finishedListener গפݫ࣌ ৮ܐؼ ٸ ঌܿਸ ߉ח ࢶఖ ܻझց */ @Composable fun animateColorAsState( targetValue: Color, animationSpec: AnimationSpec<Color> = colorDefaultSpring, finishedListener: ((Color) -> Unit)? = null ): State<Color> -
গפݫ࣌ࢎনਸݏࢸೞӝਤೠੋఠಕझ TQSJOH UXFFO LFZGSBNFT SFQFBUBCMFJOGJOJUF3FQFBUBCMF
TOBQ "OJNBUJPO4QFD -
/** * द чҗ ч ࢎী ޛܻ ӝ߈ গפݫ࣌ਸ
ਊפ. * * @param DampingRatio х࣭࠺ (ࢿ) * @param stiffness ъࢿ (ઙܐ чਵ۽ زೞח ࣘب) * @param visibleThreshold оदࢿ ҅ч * গפݫ࣌ ࢚ী ߈ৢܿೞӝী ࠙ दпਵ۽ оө Ѫਵ۽ рغযঠ ೞח दӝܳ פ. * * @return য ২࣌ਸ ࢎਊೞח [SpringSpec] */ @Stable fun <T> spring( dampingRatio: Float = Spring.DampingRatioNoBouncy, stiffness: Float = Spring.StiffnessMedium, visibilityThreshold: T? = null ): SpringSpec<T> = SpringSpec( dampingRatio = dampingRatio, stiffness = stiffness, visibilityThreshold = visibilityThreshold ) -
/** * ҋࢶਸ ࢎਊೞৈ ػ [durationMillis] زউ द чҗ
ч рী গפݫ࣌ਸ ਊפ. * * @param durationMillis গפݫ࣌ ࣘ दр (ܻୡ) * @param delayMillis গפݫ࣌ दغӝ ী ӝೞח दр (ܻୡ) * @param easing दҗ ࢎܳ ࠁрೞח ؘ ࢎਊغח ҋࢶ * * @return য ২࣌ਸ ࢎਊೞח [TweenSpec] */ @Stable fun <T> tween( durationMillis: Int = AnimationConstants.DefaultDurationMillis, delayMillis: Int = 0, easing: Easing = FastOutSlowInEasing ): TweenSpec<T> = TweenSpec( durationMillis = durationMillis, delay = delayMillis, easing = easing ) -
/** * গפݫ࣌ ࠙ࣻ(fraction)ܳ ઑೞח ߑߨੑפ. * ਸ ࢎਊೞݶ গפݫ࣌
ੌೠ ࣘب۽ ೯غח न ࣘبܳ ֫Ѣա ծ ࣻ णפ. * * ࠙ࣻח গפݫ࣌ അ ਸ աఋղח 0 ীࢲ 1.0 ࢎ чੑפ. ৈӝࢲ 0 दਸ աఋղҊ 1.0 ਸ աఋշפ. */ @Stable fun interface Easing { fun transform(fraction: Float): Float } -
// ࡅܰѱ ࣘبܳ ֫Ҋ ରਵ۽ ו۰פ. val FastOutSlowInEasing: Easing =
CubicBezierEasing(0.4f, 0.0f, 0.2f, 1.0f) // ٜযয়ח ਃࣗח ઁੌ ࡅܲ ࣘبীࢲ ו۰פ. val LinearOutSlowInEasing: Easing = CubicBezierEasing(0.0f, 0.0f, 0.2f, 1.0f) // աоח ਃࣗח ઁੌ וܽ ࣘبীࢲ ࡈۄפ. val FastOutLinearInEasing: Easing = CubicBezierEasing(0.4f, 0.0f, 1.0f, 1.0f) // ࣻغ ঋ ࠙ࣻܳ ߈ജפ. ਃೞ݅ ࣻػ ਃೞ ঋ ҃ ӝࠄчਵ۽ ਬਊפ. val LinearEasing: Easing = Easing { fraction -> fraction } // 3ର ߬য ҋࢶਸ ҳഅפ. @Immutable class CubicBezierEasing( private val a: Float, private val b: Float, private val c: Float, private val d: Float ) : Easing -
/** * গפݫ࣌ ӝрী ৈ۞ ఋझఙীࢲ ػ झշࢫ чਸ ӝ߈ਵ۽
গפݫ࣌ਸ ܻפ. * ઁա গפݫ࣌ ч ف ఃۨ ч ࢎী ࠁрؾפ. * ఃۨ݃ ࢎਊೡ [Easing] ਸ ೡ ࣻ णפ. */ @Stable fun <T> keyframes( init: KeyframesSpec.KeyframesSpecConfig<T>.() -> Unit ): KeyframesSpec<T> = KeyframesSpec( config = KeyframesSpec.KeyframesSpecConfig<T>().apply(init) ) @Composable fun KeyframesExample(target: Int) { val value by animateIntAsState( targetValue = target, // 0 ~ 100 animationSpec = keyframes { durationMillis = 1000 // 1000 ms زউ গפݫ࣌ ೯ 100 at 50 with LinearEasing // LinearEasing ਸ ࢎਊೞݴ 100 ms উী 50 ө গפݫ࣌ 500 at 80 with FastOutSlowInEasing // FastOutSlowInEasing ਸ ࢎਊೞݴ 500 ms উী 80 ө গפݫ࣌ // റ 501 ~ 1000 ms زউ ӝઓী ࢸೠ ੋ FastOutSlowInEasing ܳ ҅ࣘ ࢎਊೞৈ 100 ө গפݫ࣌ } ) } -
/** * ػ ߈ࠂ പࣻী ب׳ೡ ٸө ӝр ӝ߈ গפݫ࣌(:
[tween] ژח [keyframes])ਸ ߈ࠂਵ۽ प೯פ. * * @param iterations ߈ࠂೡ പࣻ * @param animation ߈ࠂೡ গפݫ࣌ * @param repeatMode ߈ࠂೡ ݽ٘ - [RepeatMode.Restart] ژח [RepeatMode.Reverse] * @param initialStartOffset গפݫ࣌ਸ दೡ য়ࣇ */ @Stable fun <T> repeatable( iterations: Int, animation: DurationBasedAnimationSpec<T>, repeatMode: RepeatMode = RepeatMode.Restart, initialStartOffset: StartOffset = StartOffset(0) ): RepeatableSpec<T> = RepeatableSpec( iterations = iterations, animation = animation, repeatMode = repeatMode, initialStartOffset = initialStartOffset ) -
/** * [repeatable] җ زੌೞҊ, ਬੌೠ ର ޖೠ ߈ࠂۄ iterations
ੋо হणפ. */ @Stable fun <T> infiniteRepeatable( animation: DurationBasedAnimationSpec<T>, repeatMode: RepeatMode = RepeatMode.Restart, initialStartOffset: StartOffset = StartOffset(0) ): InfiniteRepeatableSpec<T> = InfiniteRepeatableSpec( animation = animation, repeatMode = repeatMode, initialStartOffset = initialStartOffset ) -
/** * snap чਸ द ઙܐ чਵ۽ ߸ജೞח ౠࣻ
ݾ [AnimationSpec] ੑפ. * * @param delayMillis গפݫ࣌ दਸ োೡ दр (ܻୡ) */ @Stable fun <T> snap(delayMillis: Int = 0): SnapSpec<T> = SnapSpec( delay = delayMillis ) -
@Composable fun animateColorAsState( targetValue: Color, animationSpec: AnimationSpec<Color> = colorDefaultSpring, finishedListener:
((Color) -> Unit)? = null ): State<Color> -
MovieContainer { MovieName(fullname = selectedTabState.fullname) MoviePoster(posterDrawable = selectedTabState.poster) } MovieContainer
{ AnimatedContent( modifier = Modifier .align(Alignment.CenterHorizontally) .padding(horizontal = 30.dp), targetState = selectedTabState ) { tab -> MovieName(fullname = tab.fullname) } AnimatedContent( modifier = Modifier.wrapContentSize(), targetState = selectedTabState ) { tab -> MoviePoster(posterDrawable = tab.poster) } } -
/** * [targetState] о ߸҃ؼ ٸ [content] ী زਵ۽ গפݫ࣌ਸ
ਊೞח ஶపցੑפ. * * @param targetState ߸҃ؼ ࢚క * @param modifier ਊೡ [Modifier] * @param transitionSpec ਊೡ গפݫ࣌ * @param contentAlignment [content] о ߓؼ [Alignment] * @param content ߓೡ ஹನ࠶ */ @ExperimentalAnimationApi @Composable fun <S> AnimatedContent( targetState: S, modifier: Modifier = Modifier, transitionSpec: AnimatedContentScope<S>.() -> ContentTransform = { /* … */ }, contentAlignment: Alignment = Alignment.TopStart, content: @Composable AnimatedVisibilityScope.(targetState: S) -> Unit ) -
@ExperimentalAnimationApi @Composable fun <S> AnimatedContent( targetState: S, modifier: Modifier =
Modifier, transitionSpec: AnimatedContentScope<S>.() -> ContentTransform = { fadeIn( animationSpec = tween( durationMillis = 220, delayMillis = 90 ) ) + scaleIn( initialScale = 0.92f, animationSpec = tween( durationMillis = 220, delayMillis = 90 ) ) with fadeOut( animationSpec = tween(durationMillis = 90) ) }, contentAlignment: Alignment = Alignment.TopStart, content: @Composable AnimatedVisibilityScope.(targetState: S) -> Unit ) -
/** * ஹನ࠶ [AnimatedContent] ী ٜযоҊ աоח ߑߨਸ פ. *
* @param targetContentEnter ࢜۽ ஹನ࠶ ٜযয়ח গפݫ࣌ * @param initialContentExit ӝઓ ஹನ࠶ աоח গפݫ࣌ * @param targetContentZIndex ஹನ࠶ ٜযয়Ҋ աт ٸ ࢎਊೡ zIndex * @param sizeTransform ஹನ࠶ ٜযয়Ҋ աт ٸ ࢎૉо ߸ೡ ҃ ܳ ҙܻೞӝ ਤೠ ২࣌ */ @ExperimentalAnimationApi class ContentTransform( val targetContentEnter: EnterTransition, val initialContentExit: ExitTransition, targetContentZIndex: Float = 0f, sizeTransform: SizeTransform? = SizeTransform() ) { var targetContentZIndex by mutableStateOf(targetContentZIndex) var sizeTransform: SizeTransform? = sizeTransform internal set } -
@ExperimentalAnimationApi class ContentTransform( val targetContentEnter: EnterTransition, val initialContentExit: ExitTransition, targetContentZIndex:
Float = 0f, sizeTransform: SizeTransform? = SizeTransform() ) { /** * ஶపցী ٜযт ٸ ࢜۽ ࢚ ஹನ࠶ zIndex ܳ פ. * ӝࠄч 0f ੑפ. zIndex о ֫ ஹನ࠶ zIndex о ծ ஹನ࠶ ਤী Ӓ۰פ. * ੋؙझо э ஹನ࠶ ఋѶ ஹನ࠶ ݔ ਤী ߓؾפ. */ var targetContentZIndex by mutableStateOf(targetContentZIndex) /** * ࢜ ஹನ࠶ AnimatedContent ী ٜযоҊ ஹನ࠶ աт ٸ ӝо ߸҃غח ҃ ஶపց ഛ ߂ ୷ࣗܳ ҙܻפ. * ӝࠄਵ۽ [spring][SpringSpec] ݽٚ ӝ ߸҃ਸ গפݫ࣌ೞח ؘ ࢎਊغݴ [AnimatedContent] ח গפݫ࣌ػ ӝ۽ ੜ݀פ. * ࢎਊؼ [SizeTransform] ܳ ࢸೡ ࣻ णפ. ӝ গפݫ࣌ ਃೞ ঋਵݶ [sizeTransform] ਸ null ۽ ࢸೞࣁਃ. */ var sizeTransform: SizeTransform? = sizeTransform internal set } -
/** * ஹನ࠶ दؼ ٸ ೯غח গפݫ࣌ਸ פ. * ࢎਊೡ
ࣻ ח [EnterTransition] 4о పҊܻח җ эणפ. * * 1. fade: [fadeIn] * 2. scale: [scaleIn] * 3. slide: [slideIn], [slideInHorizontally], [slideInVertically] * 4. expand: [expandIn], [expandHorizontally], [expandVertically] */ @Immutable sealed class EnterTransition { internal abstract val data: TransitionData @Stable operator fun plus(enter: EnterTransition): EnterTransition { // … } } -
@Immutable sealed class EnterTransition { internal abstract val data: TransitionData
// ղࠗীࢲ ࢎਊೞח ࠁܳ ࠁҙೣ /** * ܲ [EnterTransition] ਸ Ѿפ. [EnterTransition] ח زदী दغ۽ Ѿغח ࣽࢲח ਃೞ ঋणפ. * গפݫ࣌ਸ ਊೞח ࣽࢲח ঌ ߂ ߓਯਸ ݢ ઑೞҊ ୷ࣗ ژח ഛೠ ठۄ٘פ. * * @param enter Ѿೡ ܲ [EnterTransition] * * @return 2ѐ [EnterTransition] Ѿػ ࢜۽ [EnterTransition] */ @Stable operator fun plus(enter: EnterTransition): EnterTransition { return EnterTransitionImpl( TransitionData( fade = data.fade ?: enter.data.fade, slide = data.slide ?: enter.data.slide, changeSize = data.changeSize ?: enter.data.changeSize, scale = data.scale ?: enter.data.scale ) ) } } -
/** * ஹನ࠶ ࢎۄ ٸ ೯غח গפݫ࣌ਸ פ. * ࢎਊೡ
ࣻ ח [ExitTransition] 4о పҊܻח җ эणפ. * * 1. fade: [fadeOut] * 2. scale: [scaleOut] * 3. slide: [slideOut], [slideOutHorizontally], [slideOutVertically] * 4. shrink: [shrinkOut], [shrinkHorizontally], [shrinkVertically] */ @Immutable sealed class ExitTransition { internal abstract val data: TransitionData @Stable operator fun plus(exit: ExitTransition): ExitTransition { // … } } -
@Immutable sealed class ExitTransition { internal abstract val data: TransitionData
// ղࠗীࢲ ࢎਊೞח ࠁܳ ࠁҙೣ /** * ܲ [ExitTransition] ਸ Ѿפ. [ExitTransition] ח زदী दغ۽ Ѿغח ࣽࢲח ਃೞ ঋणפ. * গפݫ࣌ਸ ਊೞח ࣽࢲח ঌ ߂ ߓਯਸ ݢ ઑೞҊ ୷ࣗ ژח ഛೠ ठۄ٘פ. * * @param exit Ѿೡ ܲ [ExitTransition] * * @return 2ѐ [ExitTransition] Ѿػ ࢜۽ [ExitTransition] */ @Stable operator fun plus(exit: ExitTransition): ExitTransition { return ExitTransitionImpl( TransitionData( fade = data.fade ?: exit.data.fade, slide = data.slide ?: exit.data.slide, changeSize = data.changeSize ?: exit.data.changeSize, scale = data.scale ?: exit.data.scale ) ) } } -
@ExperimentalAnimationApi class ContentTransform( val targetContentEnter: EnterTransition, val initialContentExit: ExitTransition, targetContentZIndex:
Float = 0f, sizeTransform: SizeTransform? = SizeTransform() ) { var targetContentZIndex by mutableStateOf(targetContentZIndex) var sizeTransform: SizeTransform? = sizeTransform internal set } -
/** * ஹನ࠶ ӝо ߸҃ؼ ٸ ೠ ӝীࢲ ܲ ӝ۽
߸ജೞח ߑߨਸ פ. */ @ExperimentalAnimationApi interface SizeTransform { /** * ࢎૉ ઑ গפݫ࣌ীࢲ ஹನ࠶ ҃҅ী ݏѱ clip ೧ঠ ೞח ৈࠗੑפ. */ val clip: Boolean /** * গפݫ࣌ ਊ ࢎૉੋ [initialSize] ৬ গפݫ࣌ ਊ റ ࢎૉੋ [targetSize] ܳ ӝ߈ਵ۽ [AnimationSpec] ਸ ٜ݅ ࣻ णפ. */ fun createAnimationSpec(initialSize: IntSize, targetSize: IntSize): FiniteAnimationSpec<IntSize> } -
@ExperimentalAnimationApi @Composable fun <S> AnimatedContent( targetState: S, modifier: Modifier =
Modifier, transitionSpec: AnimatedContentScope<S>.() -> ContentTransform = { fadeIn( animationSpec = tween( durationMillis = 220, delayMillis = 90 ) ) + scaleIn( initialScale = 0.92f, animationSpec = tween( durationMillis = 220, delayMillis = 90 ) ) with fadeOut( animationSpec = tween(durationMillis = 90) ) }, contentAlignment: Alignment = Alignment.TopStart, content: @Composable AnimatedVisibilityScope.(targetState: S) -> Unit ) -
/** * ઁҕػ [this][EnterTransition] ߂ [exit] ܳ ࢎਊೞৈ [ContentTransform] ਸ
ࢤࢿೞݴ, * [EnterTransition] ߂ [ExitTransition] গפݫ࣌ زदী प೯ؾפ. * * @param exit [this][EnterTransition] ৬ ச [ExitTransition] * * @return [this][EnterTransition] ৬ [ExitTransition] [ContentTransform] */ @ExperimentalAnimationApi infix fun EnterTransition.with(exit: ExitTransition) = ContentTransform( targetContentEnter = this, initialContentExit = exit ) -
@ExperimentalAnimationApi @Composable fun <S> AnimatedContent( targetState: S, modifier: Modifier =
Modifier, transitionSpec: AnimatedContentScope<S>.() -> ContentTransform = { /* … */ }, contentAlignment: Alignment = Alignment.TopStart, content: @Composable AnimatedVisibilityScope.(targetState: S) -> Unit ) -
/** * [AnimatedContent] ীࢲ݅ ಞܻೞѱ ਊೡ ࣻ ח ӝמਸ ઁҕפ.
*/ @ExperimentalAnimationApi class AnimatedContentScope<S> internal constructor( internal val transition: Transition<S>, internal var contentAlignment: Alignment, internal var layoutDirection: LayoutDirection ) : Transition.Segment<S> { override val initialState: S get() = transition.segment.initialState // গפݫ࣌ दغӝ ୡӝ ч override val targetState: S get() = transition.segment.targetState // গפݫ࣌ ਊؼ ч, গפݫ࣌ ઙܐ ч /** * അ [this][ContentTransform] [sizeTransform] ܳ ੋ۽ ߉ [sizeTransform] ۽ ࢸפ. * * @param sizeTransform ࢜۽ ਊೡ [SizeTransform] * * @return [sizeTransform] ਸ ࢜۽ ਊೠ [ContentTransform] */ @ExperimentalAnimationApi infix fun ContentTransform.using(sizeTransform: SizeTransform?): ContentTransform = apply { this.sizeTransform = sizeTransform } // … -
/** * ஶపց оܻীࢲ [AnimatedContent] ী ౠೠ ࣻಣ/ࣻ slide-in ਸ
פ. * [slideInHorizontally] ߂ [slideInVertically] ৬ ׳ܻ द য়ࣇ [AnimatedContent] * അ ӝ৬ ۳ ২࣌ਸ ӝ߈ਵ۽ ز ҅ؾפ. * * @param towards ठۄ٘ ߑೱ * ஹನ࠶ח [SlideDirection.Left], [SlideDirection.Right], [SlideDirection.Up] ߂ [SlideDirection.Down] * ߑೱਵ۽ ஶపցܳ ೱ೧ slide ೡ ࣻ णפ. * @param animationSpec ࢎਊೡ গפݫ࣌ * @param initialOffset द য়ࣇ. زਵ۽ ҅غ݅ द ࣻزਵ۽ ೡ ࣻب णפ. */ fun slideIntoContainer( towards: AnimatedContentScope.SlideDirection, animationSpec: FiniteAnimationSpec<IntOffset> = spring(visibilityThreshold = IntOffset.VisibilityThreshold), initialOffset: (offsetForFullSlide: Int) -> Int = { it } ): EnterTransition // slideIntoContainer ৬ زੌ, ױ slide-in न slide-out fun slideOutOfContainer( towards: AnimatedContentScope.SlideDirection, animationSpec: FiniteAnimationSpec<IntOffset> = spring(visibilityThreshold = IntOffset.VisibilityThreshold), targetOffset: (offsetForFullSlide: Int) -> Int = { it } ): ExitTransition } -
@ExperimentalAnimationApi @Composable fun <S> AnimatedContent( targetState: S, modifier: Modifier =
Modifier, transitionSpec: AnimatedContentScope<S>.() -> ContentTransform = { /* … */ }, contentAlignment: Alignment = Alignment.TopStart, content: @Composable AnimatedVisibilityScope.(targetState: S) -> Unit ) -
@Composable private fun tabBackgroundColorWithAnimation( selectedTab: Tab, nowTab: Tab ): Color
= animateColorAsState( targetValue = when (selectedTab == nowTab) { true -> TabDefaults.Color.selectedBackground false -> TabDefaults.Color.defaultBackground } ).value @Composable private fun tabTextColorWithAnimation( selectedTab: Tab, nowTab: Tab ): Color = animateColorAsState( targetValue = when (selectedTab == nowTab) { true -> TabDefaults.Color.selectedText false -> TabDefaults.Color.defaultText } ).value MovieContainer { AnimatedContent( modifier = Modifier .align(Alignment.CenterHorizontally) .padding(horizontal = 30.dp), targetState = selectedTabState ) { tab -> MovieName(fullname = tab.fullname) } AnimatedContent( modifier = Modifier.wrapContentSize(), targetState = selectedTabState, contentAlignment = Alignment.Center ) { tab -> MoviePoster(posterDrawable = tab.poster) } } -
@ExperimentalAnimationApi @Composable fun <S> AnimatedContent( targetState: S, modifier: Modifier =
Modifier, transitionSpec: AnimatedContentScope<S>.() -> ContentTransform = { fadeIn( animationSpec = tween( durationMillis = 220, delayMillis = 90 ) ) + scaleIn( initialScale = 0.92f, animationSpec = tween( durationMillis = 220, delayMillis = 90 ) ) with fadeOut( animationSpec = tween(durationMillis = 90) ) }, contentAlignment: Alignment = Alignment.TopStart, content: @Composable AnimatedVisibilityScope.(targetState: S) -> Unit ) -
MovieContainer { AnimatedContent( modifier = Modifier .align(Alignment.CenterHorizontally) .padding(horizontal = 30.dp),
targetState = selectedTabState ) { tab -> MovieName(fullname = tab.fullname) } AnimatedContent( modifier = Modifier.wrapContentSize(), targetState = selectedTabState, contentAlignment = Alignment.Center ) { tab -> MoviePoster(posterDrawable = tab.poster) } } MovieContainer { AnimatedContent( modifier = Modifier .align(Alignment.CenterHorizontally) .padding(horizontal = 30.dp), targetState = selectedTabState, transitionSpec = { fadeIn() with fadeOut() using SizeTransform(clip = false) } ) { tab -> MovieName(fullname = tab.fullname) } // … } -
MovieContainer { // … AnimatedContent( modifier = Modifier.wrapContentSize(), targetState =
selectedTabState, contentAlignment = Alignment.Center, transitionSpec = { val targetIndex = targetState.index // targetState == Tab val initialIndex = initialState.index // initialState == Tab if (targetIndex > initialIndex) { // చ slideIntoContainer( towards = AnimatedContentScope.SlideDirection.Start ) with fadeOut() using SizeTransform(clip = false) } else { // చ fadeIn() with slideOutOfContainer( towards = AnimatedContentScope.SlideDirection.End ) using SizeTransform(clip = false) }.apply { targetContentZIndex = targetIndex.toFloat() } } ) { tab -> MoviePoster(posterDrawable = tab.poster) } } MovieContainer { AnimatedContent( modifier = Modifier .align(Alignment.CenterHorizontally) .padding(horizontal = 30.dp), targetState = selectedTabState ) { tab -> MovieName(fullname = tab.fullname) } AnimatedContent( modifier = Modifier.wrapContentSize(), targetState = selectedTabState, contentAlignment = Alignment.Center ) { tab -> MoviePoster(posterDrawable = tab.poster) } } -
/** * ࢚క ࣻળীࢲ ݽٚ গפݫ࣌ਸ ҙܻפ. * গפݫ࣌ [Transition.animateFloat],
[Transition.animateColor], [Transition.animateValue] ١ਸ * ࢎਊೞৈ ࢶੋ ߑधਵ۽ ٜ݅ ࣻ णפ. * * @param initialState গפݫ࣌ ୡӝ ч * @param label Android Studio Animation Inspector ীࢲ [Transition] ਸ ҳ߹ೞח ؘ ࢎਊೡ కӒ */ @Stable class Transition<S> @PublishedApi internal constructor( initialState: S, label: String? ) -
/** * [Transition] ਸ ࢤࢿೞҊ [targetState] чਵ۽ ୡӝ ࢚కܳ פ.
* [targetState] о ߸҃غݶ [Transition] ࢜ [targetState] чਵ۽ ٜ݅য ݽٚ গפݫ࣌ਸ ઑפ. * * @param targetState ߸҃ਸ хೡ ࢚ * @param label Android Studio Animation Inspector ীࢲ [Transition] ਸ ҳ߹ೞח ؘ ࢎਊೡ కӒ * * @return [targetState] чਵ۽ ୡӝ ࢚కо ػ [Transition] */ @Composable fun <T> updateTransition( targetState: T, label: String? = null ): Transition<T> -
/** * ػ [Transition] ী ࢝ӭ গפݫ࣌ਸ ୶оפ. * ח
গפݫ࣌ ࢤݺ ӝо [Transition] ী ೧ ҙܻؽਸ פ. * * @param transitionSpec ਊೡ গפݫ࣌ * @param label Android Studio Animation Inspector ীࢲ [Transition] ਸ ҳ߹ೞח ؘ ࢎਊೡ కӒ * @param targetValueByState ػ [Transition] গפݫ࣌ दعਸ ٸ ઁҕೡ ч * * @return গפݫ࣌ ਊػ [Color] [State] */ @Composable inline fun <S> Transition<S>.animateColor( noinline transitionSpec: @Composable Transition.Segment<S>.() -> FiniteAnimationSpec<Color> = { spring() }, label: String = "ColorAnimation", targetValueByState: @Composable (state: S) -> Color ): State<Color> -
/** * ࢚ਤ [Transition] ࢚క৬ ೞਤ ࢚క р ݒೝਸ
ӝ߈ਵ۽ ೞਤ [Transition] ਸ ٟ݅פ. * ח җ э ਊب۽ ࢎਊؾפ: * * 1. ೞਤ [Transition] ࢚కܳ ࢚ਤ [Transition] ਵ۽ ഐझ * ࢚ਤ [Transition] زੌೠ ࢚ ࢚క ߸҃ਵ۽ ੋ೧ ೯ ੋ গפݫ࣌ ח ৈࠗܳ ੋधפ. * ۧѱ ೞݶ ࢎী ೯؍ গפݫ࣌ ৮ܐغਸ ٸ ࣽରਵ۽ ܲ গפݫ࣌ਸ ࢸೡ ࣻ णפ. * * 2. ҙबࢎ ܻ࠙ * ࢚ਤ [Transition] ীࢲ ߉ ࢚కীࢲ ࢎਊೞח ࠁ݅ ఠ݂ೞৈ ೞਤ۽ ׳ೞҊ रਸ ٸ ਬਊೞѱ ॳੌ ࣻ णפ. * * @param label Android Studio Animation Inspector ীࢲ [Transition] ਸ ҳ߹ೞח ؘ ࢎਊೡ కӒ * @param transformToChildState ࢚ਤ [Transition] ীࢲ чਸ ߉Ҋ ࢜۽ ݅ٚ ࢚క ч * * @return ࢜۽ ࢚కܳ оח ೞਤ [Transition] */ @ExperimentalTransitionApi @Composable inline fun <S, T> Transition<S>.createChildTransition( label: String = "ChildTransition", transformToChildState: @Composable (parentState: S) -> T ): Transition<T> -
var selectedTabState by remember { mutableStateOf(TabDefaults.Items.first()) } val selectedTabTypeTransition =
updateTransition( targetState = selectedTabState.type, label = "selected tab" ) // … TabContainer { TabDefaults.Items.forEach { tab -> val backgroundColor by selectedTabTypeTransition.animateColor( transitionSpec = { defaultTween() }, label = "background color" ) { movie -> when (movie == tab.type) { true -> TabDefaults.Color.selectedBackground false -> TabDefaults.Color.defaultBackground } } val textColor by selectedTabTypeTransition.animateColor( transitionSpec = { defaultTween() }, label = "text color" ) { movie -> when (movie == tab.type) { true -> TabDefaults.Color.selectedText -
) { movie -> when (movie == tab.type) { true
-> TabDefaults.Color.selectedBackground false -> TabDefaults.Color.defaultBackground } } val textColor by selectedTabTypeTransition.animateColor( transitionSpec = { defaultTween() }, label = "text color" ) { movie -> when (movie == tab.type) { true -> TabDefaults.Color.selectedText false -> TabDefaults.Color.defaultText } } TabItem( title = tab.shortname, backgroundColor = backgroundColor, textColor = textColor, onTabClick = { selectedTabState = tab } ) } } -
MovieContainer { AnimatedContent( modifier = Modifier .align(Alignment.CenterHorizontally) .padding(horizontal = 30.dp),
targetState = selectedTabState, // … ӝઓҗ زੌ ) { tab -> MovieName(fullname = tab.fullname) } AnimatedContent( modifier = Modifier.wrapContentSize(), targetState = selectedTabState, // … ӝઓҗ زੌ ) { tab -> MoviePoster(posterDrawable = tab.poster) } } -
/** * [this][Transition] targetState о ߸҃ؼ ٸ زਵ۽ [content]
ী গפݫ࣌ਸ ਊೞח ஶపցੑפ. * * @param modifier ਊೡ [Modifier] * @param transitionSpec ਊೡ গפݫ࣌ * @param contentAlignment [content] о ߓؼ [Alignment] * @param contentKey [Transition] targetState ী ೠ ః. زੌೠ ఃܳ ҕਬೞח ߸҃ੌ ҃ গפݫ࣌ ೯غ ঋणפ. * @param content ߓೡ ஹನ࠶ */ @ExperimentalAnimationApi @Composable fun <S> Transition<S>.AnimatedContent( modifier: Modifier = Modifier, transitionSpec: AnimatedContentScope<S>.() -> ContentTransform = { // ӝઓ AnimatedContent ৬ زੌ }, contentAlignment: Alignment = Alignment.TopStart, contentKey: (targetState: S) -> Any? = { it }, content: @Composable AnimatedVisibilityScope.(targetState: S) -> Unit ) -
MovieContainer { selectedTabTypeTransition .createChildTransition(label = "selected tab fullname") { movie
-> movie.fullname } .AnimatedContent(/* ӝઓҗ زੌ */) { tabFullname -> MovieName(fullname = tabFullname) } selectedTabTypeTransition .AnimatedContent(/* ӝઓҗ زੌ */) { movie -> MoviePoster(posterDrawable = movie.poster) } } -
@Composable private fun MovieTab( selectedTabTypeTransition: Transition<Movie>, updateSelectedTab: (tab: Tab) ->
Unit ) { BoxWithConstraints( modifier = Modifier .fillMaxWidth() .wrapContentHeight() .clip( RoundedCornerShape( bottomStartPercent = DefaultCornerUnit, bottomEndPercent = DefaultCornerUnit ) ) ) { val backgroundBoxWidth = remember { maxWidth / TabDefaults.Items.count() } val backgroundOffsetTransition by selectedTabTypeTransition.animateIntOffset( transitionSpec = { defaultTween() }, label = "background offset" ) { movie -> IntOffset( x = with(LocalDensity.current) { (eachItemWidth * movie.index).toPx() }.toInt(), -
) ) { val eachItemWidth = remember { maxWidth /
TabDefaults.Items.count() } val backgroundOffsetTransition by selectedTabTypeTransition.animateIntOffset( transitionSpec = { defaultTween() }, label = "background offset" ) { movie -> IntOffset( x = with(LocalDensity.current) { (backgroundBoxWidth * movie.index).toPx() // dp -> float }.toInt(), // float -> int y = 0 ) } val backgroundShapeTransition by selectedTabTypeTransition.animateValue( transitionSpec = { defaultTween() }, label = "background shape", typeConverter = TwoWayConverter( convertToVector = { corner -> AnimationVector4D( v1 = corner.topStart.toPercent(), v2 = corner.topEnd.toPercent(), v3 = corner.bottomStart.toPercent(), v4 = corner.bottomEnd.toPercent() ) }, convertFromVector = { vector -> -
/** * গפݫ࣌ী ࢎਊغח ݽٚ ؘఠ ਬഋ ରਗী ٮۄ *
[AnimationVector1D], [AnimationVector2D], [AnimationVector3D] ژח [AnimationVector4D] ۽ ߸ജؾפ. * ٮۄࢲ ё ৈ۞ ҳࢿਃࣗܳ пп ࣘب ୶ ӝמਸ ࢎਊೞৈ ة݀ਵ۽ গפݫ࣌ ܻೡ ࣻ णפ. * * ܳ ٜয [Color] ח A, R, G, B 4ѐ ҳࢿ ਃࣗ۽ ܖযઉ णפ. * ٮۄࢲ [AnimationVector4D] ܳ ࢎਊפ. */ sealed class AnimationVector { internal abstract fun reset() internal abstract fun newVector(): AnimationVector internal abstract operator fun get(index: Int): Float internal abstract operator fun set(index: Int, value: Float) internal abstract val size: Int } -
/** * ఋੑ [T] ীࢲ [AnimationVector] ۽ ߸ജೞҊ [AnimationVector]
ܳ द ఋੑ [T] ۽ ߸ജೞח ߑߨী ೠ о ನೣغয णפ. * ܳ ా೧ গפݫ࣌ਸ ݽٚ ఋੑ ѐীࢲ ҳഅೡ ࣻ णפ. */ interface TwoWayConverter<T, V : AnimationVector> { /** * ఋੑ [T] ਸ [AnimationVector] ఋੑਵ۽ ߸ജೞח ߑߨਸ פ. */ val convertToVector: (T) -> V /** * [AnimationVector] ఋੑਸ द ఋੑ [T] ۽ ߸ജೞח ߑߨਸ פ. */ val convertFromVector: (V) -> T } -
) } val backgroundShapeTransition by selectedTabTypeTransition.animateValue( transitionSpec = { defaultTween()
}, label = "background shape", typeConverter = TwoWayConverter( convertToVector = { corner -> AnimationVector4D( v1 = corner.topStart.getPercent(), v2 = corner.topEnd.getPercent(), v3 = corner.bottomStart.getPercent(), v4 = corner.bottomEnd.getPercent() ) }, convertFromVector = { vector -> RoundedCornerShape( topStartPercent = vector.v1.toInt(), topEndPercent = vector.v2.toInt(), bottomStartPercent = vector.v3.toInt(), bottomEndPercent = vector.v4.toInt() ) } ) ) { movie -> when (movie) { Movie.Thor -> RoundedCornerShape(bottomStartPercent = 30) Movie.Spider -> RoundedCornerShape(percent = 0) -
) ) { movie -> when (movie) { Movie.Thor ->
RoundedCornerShape(bottomStartPercent = 30) // ৽ଃ -> ৽ଃ ೞױ݅ ۄ٬ Movie.Spider -> RoundedCornerShape(percent = 0) // оؘ -> ۄ٬ X Movie.Doctor -> RoundedCornerShape(bottomEndPercent = 30) // য়ܲଃ -> য়ܲଃ ೞױ݅ ۄ٬ } } TabContainer { TabDefaults.Items.forEach { tab -> val textColor by selectedTabTypeTransition.animateColor( transitionSpec = { defaultTween() }, label = "text color" ) { movie -> when (movie == tab.type) { true -> TabDefaults.Color.selectedText false -> TabDefaults.Color.defaultText } } TabItem( title = tab.shortname, backgroundColor = TabDefaults.Color.defaultBackground, textColor = textColor, onTabClick = { -
false -> TabDefaults.Color.defaultText } } TabItem( title = tab.shortname, backgroundColor
= TabDefaults.Color.defaultBackground, textColor = textColor, onTabClick = { updateSelectedTab(tab) } ) } } Box( modifier = Modifier .width(backgroundBoxWidth) .height(TabDefaults.Height) .offset { backgroundOffsetTransition } .clip(backgroundShapeTransition) .background(color = TabDefaults.Color.selectedBackground) ) } } -
fun Modifier.movement(lookaheadScope: LookaheadLayoutScope) = composed { var targetOffset: IntOffset? by
remember { mutableStateOf(null) } var placementOffset by remember { mutableStateOf(IntOffset.Zero) } // 1. ӝࠄч হ: animateAsState X // 2. গפݫ࣌ чਵ۽ ೧ ч হ: Transition X with(lookaheadScope) { this@composed .onPlaced { lookaheadScopeCoordinates, layoutCoordinates -> targetOffset = lookaheadScopeCoordinates .localLookaheadPositionOf(sourceCoordinates = layoutCoordinates) .round() placementOffset = lookaheadScopeCoordinates .localPositionOf( sourceCoordinates = layoutCoordinates, relativeToSource = Offset.Zero ) .round() } .intermediateLayout { measurable, constraints, _ -> val placeable = measurable.measure(constraints) layout(width = placeable.width, height = placeable.height) { val (x, y) = targetOffset!! - placementOffset -
fun Modifier.transformation(lookaheadScope: LookaheadLayoutScope) = with(lookaheadScope) { intermediateLayout { measurable, _,
lookaheadSize -> val (width, height) = lookaheadSize // 1. ӝࠄч হ: animateAsState X // 2. গפݫ࣌ чਵ۽ ೧ ч হ: Transition X val animatedConstraints = Constraints.fixed( width = width.coerceAtLeast(0), height = height.coerceAtLeast(0) ) val placeable = measurable.measure(animatedConstraints) layout(width = placeable.width, height = placeable.height) { placeable.place(x = 0, y = 0) } } } -
/** * [animateTo] ܳ ా೧ ч ߸҃ؼ ٸ زਵ۽ чী
গפݫ࣌ਸ ਊೞח ч ഓ؊ੑפ. */ class Animatable<T, V : AnimationVector>( initialValue: T, // ୡӝ ч val typeConverter: TwoWayConverter<T, V>, // গפݫ࣌ ёী ࢎਊೡ AnimationVector private val visibilityThreshold: T? = null // оदࢿ ҅ч ) { // গפݫ࣌ അ ч val value: T get() = internalState.value // അ গפݫ࣌ ࢚. গפݫ࣌ ױ হ աݶ ݾ чী ب׳פ. var taretValue: T by mutableStateOf(initialValue) private set // targetValue чਸ ೱ೧ গפݫ࣌ਸ दפ. block ੋח ݒ গפݫ࣌ ۨ ݃ ഐؾפ. suspend fun animateTo( targetValue: T, animationSpec: AnimationSpec<T> = defaultSpringSpec, initialVelocity: T = velocity, block: (Animatable<T, V>.() -> Unit)? = null ): AnimationResult<T, V> } -
fun Modifier.animateMovement( lookaheadScope: LookaheadLayoutScope, animationSpec: AnimationSpec<IntOffset> = defaultSpring() ) =
composed { var placementOffset by remember { mutableStateOf(IntOffset.Zero) } var targetOffset: IntOffset? by remember { mutableStateOf(null) } var targetOffsetAnimation: Animatable<IntOffset, AnimationVector2D>? by remember { mutableStateOf(null) } LaunchedEffect(Unit) { snapshotFlow { targetOffset }.collect { target -> if (target != null && target != targetOffsetAnimation?.targetValue) { targetOffsetAnimation?.run { launch { animateTo( targetValue = target, animationSpec = animationSpec ) } } ?: Animatable( initialValue = target, typeConverter = IntOffset.VectorConverter ).let { offsetAnimatable -> -
animationSpec = animationSpec ) } } ?: Animatable( initialValue =
target, typeConverter = IntOffset.VectorConverter ).let { offsetAnimatable -> targetOffsetAnimation = offsetAnimatable } } } } with(lookaheadScope) { this@composed .onPlaced { /* ӝઓҗ زੌ */ } .intermediateLayout { measurable, constraints, _ -> val placeable = measurable.measure(constraints) layout(width = placeable.width, height = placeable.height) { val (x, y) = (targetOffsetAnimation?.value ?: targetOffset!!) - placementOffset placeable.place(x = x, y = y) } } } } -
fun Modifier.animateTransformation( lookaheadScope: LookaheadLayoutScope, animationSpec: AnimationSpec<IntSize> = defaultSpring() ) =
composed { var targetSize: IntSize? by remember { mutableStateOf(null) } var targetSizeAnimation: Animatable<IntSize, AnimationVector2D>? by remember { mutableStateOf(null) } LaunchedEffect(Unit) { snapshotFlow { targetSize }.collect { target -> if (target != null && target != targetSizeAnimation?.targetValue) { targetSizeAnimation?.run { launch { animateTo( targetValue = target, animationSpec = animationSpec ) } } ?: Animatable( initialValue = target, typeConverter = IntSize.VectorConverter ).let { sizeAnimatable -> targetSizeAnimation = sizeAnimatable } -
} ?: Animatable( initialValue = target, typeConverter = IntSize.VectorConverter ).let
{ sizeAnimatable -> targetSizeAnimation = sizeAnimatable } } } } with(lookaheadScope) { [email protected] { measurable, _, lookaheadSize -> targetSize = lookaheadSize val (width, height) = targetSizeAnimation?.value ?: lookaheadSize val animatedConstraints = Constraints.fixed( width = width.coerceAtLeast(0), height = height.coerceAtLeast(0) ) val placeable = measurable.measure(animatedConstraints) layout(width = placeable.width, height = placeable.height) { placeable.place(x = 0, y = 0) } } } -
ೞա"OJNBUJPO4QFD݅оמ ೞաগפݫ࣌݅оמ ೞաఋੑ݅оמ "OJNBUF <5> 4UBUF 4UBUF
<5> "OJNBUF"T4UBUF "OJNBUJPO 4QFD PCKFDU PCKFDU -
ৈ۞ѐ"OJNBUJPO4QFDоמ ৈ۞ѐগפݫ࣌оמ ೞաఋੑ݅оמ "OJNBUBCMF <5> 4UBUF <5>
PCKFDU PCKFDU BOJNBUF5P BOJNBUF5P "OJNBUJPO 4QFD "OJNBUJPO 4QFD "OJNBUBCMF -
ৈ۞ѐ"OJNBUJPO4QFDоמ ৈ۞ѐগפݫ࣌оמ ৈ۞ѐఋੑоמ উ٘۽٘झౚ٣য়JOTQFDUоמ 5SBOTJUJPO
<5> 4UBUF <5> 5SBOTJUJPO PCKFDU PCKFDU BOJNBUF <5> BOJNBUF <5> "OJNBUJPO 4QFD "OJNBUJPO 4QFD -
fun earth() { print(LiveLiterals$EarthKt.`getString$arg-0$call-print$fun-earth`()) } object LiveLiterals$EarthKt { var `String$arg-0$call-print$fun-earth`
= "Bye World" var `State$String$arg-0$call-print$fun-earth`: MutableState<String>? = null fun `getString$arg-0$call-print$fun-earth`(): String { val field = this.`String$arg-0$call-print$fun-earth` val state = if (field == null) { val tmp = liveLiteral( "String$arg-0$call-print$fun-earth", this.`String$arg-0$call-print$fun-earth` ) this.`String$arg-0$call-print$fun-earth` = tmp tmp } else field return field.value } } -
fun earth() { print(LiveLiterals$EarthKt.`getString$arg-0$call-print$fun-earth`()) } object LiveLiterals$EarthKt { var `String$arg-0$call-print$fun-earth`
= "Bye World" var `State$String$arg-0$call-print$fun-earth`: MutableState<String>? = null fun `getString$arg-0$call-print$fun-earth`(): String { val field = this.`String$arg-0$call-print$fun-earth` val state = if (field == null) { val tmp = liveLiteral( "String$arg-0$call-print$fun-earth", this.`String$arg-0$call-print$fun-earth` ) this.`String$arg-0$call-print$fun-earth` = tmp tmp } else field return field.value } } -
fun earth() { print(LiveLiterals$EarthKt.`getString$arg-0$call-print$fun-earth`()) } object LiveLiterals$EarthKt { var `String$arg-0$call-print$fun-earth`
= "Bye World" var `State$String$arg-0$call-print$fun-earth`: MutableState<String>? = null fun `getString$arg-0$call-print$fun-earth`(): String { val field = this.`String$arg-0$call-print$fun-earth` val state = if (field == null) { val tmp = liveLiteral( "String$arg-0$call-print$fun-earth", this.`String$arg-0$call-print$fun-earth` ) this.`String$arg-0$call-print$fun-earth` = tmp tmp } else field return field.value } } -
fun earth() { print(LiveLiterals$EarthKt.`getString$arg-0$call-print$fun-earth`()) } object LiveLiterals$EarthKt { var `String$arg-0$call-print$fun-earth`
= "Bye World" var `State$String$arg-0$call-print$fun-earth`: MutableState<String>? = null fun `getString$arg-0$call-print$fun-earth`(): String { val field = this.`String$arg-0$call-print$fun-earth` val state = if (field == null) { val tmp = liveLiteral( "String$arg-0$call-print$fun-earth", this.`String$arg-0$call-print$fun-earth` ) this.`String$arg-0$call-print$fun-earth` = tmp tmp } else field return field.value } } -
fun earth() { print(LiveLiterals$EarthKt.`getString$arg-0$call-print$fun-earth`()) } object LiveLiterals$EarthKt { var `String$arg-0$call-print$fun-earth`
= "Bye World" var `State$String$arg-0$call-print$fun-earth`: MutableState<String>? = null fun `getString$arg-0$call-print$fun-earth`(): String { val field = this.`String$arg-0$call-print$fun-earth` val state = if (field == null) { val tmp = liveLiteral( "String$arg-0$call-print$fun-earth", this.`String$arg-0$call-print$fun-earth` ) this.`String$arg-0$call-print$fun-earth` = tmp tmp } else field return field.value } } -
fun earth() { print(LiveLiterals$EarthKt.`getString$arg-0$call-print$fun-earth`()) } object LiveLiterals$EarthKt { var `String$arg-0$call-print$fun-earth`
= "Bye World" var `State$String$arg-0$call-print$fun-earth`: MutableState<String>? = null fun `getString$arg-0$call-print$fun-earth`(): String { val field = this.`String$arg-0$call-print$fun-earth` val state = if (field == null) { val tmp = liveLiteral( "String$arg-0$call-print$fun-earth", this.`String$arg-0$call-print$fun-earth` ) this.`String$arg-0$call-print$fun-earth` = tmp tmp } else field return field.value } } -
fun earth() { print(LiveLiterals$EarthKt.`getString$arg-0$call-print$fun-earth`()) } object LiveLiterals$EarthKt { var `String$arg-0$call-print$fun-earth`
= "Bye World" var `State$String$arg-0$call-print$fun-earth`: MutableState<String>? = null fun `getString$arg-0$call-print$fun-earth`(): String { val field = this.`String$arg-0$call-print$fun-earth` val state = if (field == null) { val tmp = liveLiteral( "String$arg-0$call-print$fun-earth", this.`String$arg-0$call-print$fun-earth` ) this.`String$arg-0$call-print$fun-earth` = tmp tmp } else field return field.value } } -
private val liveLiteralCache = HashMap<String, MutableState<Any?>>() @InternalComposeApi @ComposeCompilerApi fun <T>
liveLiteral(key: String, value: T): State<T> { return liveLiteralCache.getOrPut(key) { mutableStateOf(value) } as State<T> } -
@InternalComposeApi fun updateLiveLiteralValue(key: String, value: Any?) { var needToUpdate =
true val stateObj = liveLiteralCache.getOrPut(key) { needToUpdate = false mutableStateOf(value) } if (needToUpdate) { stateObj.value = value } } -
private fun findEffectiveRecomposeScope(group: Int): RecomposeScopeImpl? { var current = group
while (current > 0) { for (data in DataIterator(this, current)) { if (data is RecomposeScopeImpl) { return data } } current = groups.parentAnchor(current) } return null } -
// @Composable XXX fun earth() { print(LiveLiterals$EarthKt.`getString$arg-0$call-print$fun-earth`()) } object LiveLiterals$EarthKt
{ var `String$arg-0$call-print$fun-earth` = "Bye World" var `State$String$arg-0$call-print$fun-earth`: MutableState<String>? = null fun `getString$arg-0$call-print$fun-earth`(): String { val field = this.`String$arg-0$call-print$fun-earth` val state = if (field == null) { val tmp = liveLiteral( "String$arg-0$call-print$fun-earth", this.`String$arg-0$call-print$fun-earth` ) this.`String$arg-0$call-print$fun-earth` = tmp tmp } else field return field.value } } -
/** * LiveLiteral ெઉ ח ҃ীب ਊغח ߧਤ ղীࢲ
LiveLiteral ਸ ࢤࢿೞ ঋب۾ * ஹನૉ ஹੌ۞ী दೞח ؘ ࢎਊؾפ. */ @Target( AnnotationTarget.PROPERTY, AnnotationTarget.FUNCTION, AnnotationTarget.CLASS, AnnotationTarget.FILE ) @Retention(AnnotationRetention.SOURCE) annotation class NoLiveLiterals @NoLiveLiterals fun earth() { print("Bye World") } -
/** * উ ࢚కח ѱ 3о ઑѤਸ ٮܵפ. * *
- ч ߸҃عਸ ҃ ஹನ࠶ীѱ ঌ۰ઉঠ פ. (, [State] ۽ زظঠ ೣ) * - ੋझఢझ৬ അ ੋझఢझо زੌ೧ঠ פ. * - ݽٚ ҕѐ ٜ٘ب উ ࢚కৈঠ פ. * * 3о ઑѤਸ ٮܲݶ ஹನૉח ೧ ٘о উੋ ࢚కۄҊ ঈೞҊ, * ೧ ٘ ч ߄Շ ঋওݶ ࢎਊػ ஹನ࠶ ܻஹನ࣌ਸ ࢤۚפ. * * @see Immutable * @see Stable */ @Target(AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.CLASS) @Retention(AnnotationRetention.BINARY) annotation class StableMarker -
/** * ࢤࢿػ റ۽ ݽٚ ҕѐੋ ٘о ߸ೞ ঋחח
Ѫਸ աఋղݴ ېझী ਊؼ ࣻ णפ. * * ࢤࢿ റ ч ߸҃غ ঋਵ۽ উ ߣ૩ ӏੋ * "ч ߸҃عਸ ҃ ஹನ࠶ীѱ ঌ۰ઉঠ פ." о ޖदؾפ. */ @Target(AnnotationTarget.CLASS) @Retention(AnnotationRetention.BINARY) @StableMarker annotation class Immutable fun main() { val list = mutableListOf(1) list.add(2) // ੋझఢझח زੌೞ݅ ч ߄Չ ࣻ णפ. // @Immutable ۞ೠ ߸҃ب ೲਊೞ ঋणפ. } -
/** * ч ߸҃ؼ ࣻ ח ࢚కݴ, ਊ ࢚ী ٮۄ
ডрঀ ೡ ׳ۄפ. * * ఋੑী ਊػݶ ୶о ೡ হ [StableMarker] ೡਸ Ӓ۽ оઉцפ. * * ೣࣻա ۽ಌ౭ী ਊػݶ [StableMarker] ೡী ୶оغח ೡ ࢤӤפ. * э input ী যࢲח ೦࢚ زੌೠ output ਸ ٜ݅যղݴ(ࣽࣻ ೣࣻ), ೣࣻ ҃ ੋٜ द ݽف উੋ ࢚కۄח Ѫਸ ডࣘפ. * ݅ড input زੌೞݶ output ژೠ زੌೡ Ѫӝ ٸޙী ܻஹನ࣌ਸ झఈೞѱ ؾפ. */ @Target( AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY ) @Retention(AnnotationRetention.BINARY) @StableMarker annotation class Stable -
/** * ஹੌ दী ݽٚ ېझٜ উࢿਸ زਵ۽ ୶ۿפ. *
* @param parameters উࢿਸ ୶ۿೞחؘ ب ؼ ࣻ ѱ ੋٜ ࠺݃झܳ աఋշפ. */ @ComposeCompilerApi @Target(AnnotationTarget.CLASS) @Retention(AnnotationRetention.BINARY) annotation class StabilityInferred(val parameters: Int) // ਬੌೠ ٘ੋ value о উ ࢚కҊ ࠛ߸ೞӝ ٸޙী Name ېझח উ ࢚క۽ ౸ױؾפ. class Name(val value: String) // ਬੌೠ ٘ੋ value ఋੑ ઁ֎ܼۄ ఋੑਸ ౸ױೡ ࣻ হӝী ࢎী ࠺݃झఊػ чਸ ӝળਵ۽ উ ࢚కܳ ୶ۿפ. // ೞ݅ ٘о о߸ ࢚కӝ ٸޙী T ఋੑ উৈب NameWithGeneric ېझח ࠛউ ࢚క۽ ౸ױؾפ. class NameWithGeneric<T>(var value: T) -
public interface MutableList<E> : List<E>, MutableCollection<E> @Composable fun TextWithImmutableList(texts: List<String>
= mutableListOf()) { Text(text = texts.joinToString()) } -
@Immutable class ImmutableListWrapper(val values: List<String>) @Composable fun TextWithImmutableList(texts: ImmutableListWrapper) {
Text(text = texts.values.joinToString()) } -
CVJMENFUSJDT // ஹੌ۞о хೠ ஹನ࠶ ೣٜࣻ ࠁܳ աఋշפ. kotlinOptions {
freeCompilerArgs += [ "-P", "plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=" + "${rootProject.file(".").absolutePath}/report/compose-metrics" ] } -
<ݽٕݺ>@<࠽٘ఋੑ>NPEVMFKTPO { { "skippableComposables": 48, // skippable ࢚కੋ ஹನ࠶ ѐࣻ
"restartableComposables": 67, "readonlyComposables": 0, "totalComposables": 67, // ஹನ࠶ ѐࣻ "restartGroups": 67, "totalGroups": 72, "staticArguments": 130, "certainArguments": 28, "knownStableArguments": 793, // উ ࢚క۽ ঌ۰ ੋ ѐࣻ "knownUnstableArguments": 30, // ࠛউ ࢚క۽ ঌ۰ ੋ ѐࣻ "unknownStableArguments": 8, "totalArguments": 831, "markedStableClasses": 0, "inferredStableClasses": 16, // উ ࢚క۽ ୶ۿػ ېझ ѐࣻ "inferredUnstableClasses": 2, // ࠛউ ࢚క۽ ୶ۿػ ېझ ѐࣻ "inferredUncertainClasses": 0, "effectivelyStableClasses": 16, "totalClasses": 18, "memoizedLambdas": 54, "singletonLambdas": 5, "singletonComposableLambdas": 8, "composableLambdas": 31, "totalLambdas": 89 } -
CVJMESFQPSUT // ஹੌ۞о хೠ ஹನ࠶ ೣٜࣻ ࢎਊੋ ېझ৬ ੋী ೠ
উࢿ ࠁܳ աఋշפ. kotlinOptions { freeCompilerArgs += [ "-P", "plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=" + "${rootProject.file(".").absolutePath}/report/compose-reports" ] } -
<ݽٕݺ>@<࠽٘ఋੑ>DMBTTFTUYU /* ——— classes ——— */ sealed class UiState {
object Loading : UiState() object Done : UiState() data class Exception(val throwable: Throwable) : UiState() } /* ——— reports ——— */ stable class Loading { <runtime stability> = Stable } stable class Done { <runtime stability> = Stable } unstable class Exception { unstable val throwable: Throwable <runtime stability> = Unstable } -
<ݽٕݺ>@<࠽٘ఋੑ>DPNQPTBCMFTDTW /* ——— composables ——— */ @Composable fun DisplayText(text: String
= "Hi") { Text(text = text) } @Composable fun DisplayTexts(texts: List<String>) { Text(text = texts.joinToString()) } /* ——— reports ——— */ -
<ݽٕݺ>@<࠽٘ఋੑ>DPNQPTBCMFTUYU /* ——— composables ——— */ @Composable fun DisplayText(text: String
= "Hi") { Text(text = text) } @Composable fun DisplayTexts(texts: List<String>) { Text(text = texts.joinToString()) } /* ——— reports ——— */ restartable skippable scheme("[androidx.compose.ui.UiComposable]") fun DisplayText( stable text: String? = @dynamic LiveLiterals$MainActivityKt.String$param-text$fun-DisplayText() ) restartable /* skippable হ */ scheme("[androidx.compose.ui.UiComposable]") fun DisplayTexts( unstable texts: List<String> ) -
<ݽٕݺ>@<࠽٘ఋੑ>DPNQPTBCMFTUYU /* ——— composables ——— */ @Composable fun DisplayText(text: String
= "Hi") { Text(text = text) } @Composable fun DisplayTexts(texts: List<String>) { Text(text = texts.joinToString()) } /* ——— reports ——— */ restartable skippable scheme("[androidx.compose.ui.UiComposable]") fun DisplayText( stable text: String? = @dynamic LiveLiterals$MainActivityKt.String$param-text$fun-DisplayText() ) restartable scheme("[androidx.compose.ui.UiComposable]") fun DisplayTexts( unstable texts: List<String> ) -
<ݽٕݺ>@<࠽٘ఋੑ>DPNQPTBCMFTUYU /* ——— composables ——— */ @NoLiveLiterals // new @Composable
fun DisplayText(text: String = "Hi") { Text(text = text) } @Composable fun DisplayTexts(texts: List<String>) { Text(text = texts.joinToString()) } /* ——— reports ——— */ restartable skippable scheme("[androidx.compose.ui.UiComposable]") fun DisplayText( stable text: String? = @static "Hi" ) restartable scheme("[androidx.compose.ui.UiComposable]") fun DisplayTexts( unstable texts: List<String> ) -
EPOVUIPMFTLJQQJOH setContent { var number by remember { mutableStateOf(0) }
println("setContent recomposition") Text( modifier = Modifier.clickable { number++ }, text = number.toString() ).also { println("Text recomposition") } } /* ܻஹನ࣌ য٣ী ೯ؼөਃ? 1, setContent content 2. Text 3. setContent content + Text */ -
EPOVUIPMFTLJQQJOH setContent { var number by remember { mutableStateOf(0) }
println("setContent recomposition") Text( modifier = Modifier.clickable { number++ }, text = number.toString() ).also { println("Text recomposition") } } /* [first-composition] setContent recomposition Text recomposition [re-composition] setContent recomposition Text recomposition റ زੌ ۽Ӓ ߈ࠂ */ -
EPOVUIPMFTLJQQJOH setContent { var number by remember { mutableStateOf(0) }
println("setContent recomposition") Button(onClick = { number++ }) { Text( text = number.toString() ).also { println("Text recomposition") } }.also { println("Button recomposition") } } /* [first-composition] setContent recomposition Text recomposition Button recomposition [re-composition] Text recomposition റ زੌ ۽Ӓ ߈ࠂ */ -
EPOVUIPMFTLJQQJOH // ஹੌ @Composable fun TextWrapper(text: String) { Text(text
= text) } // ஹੌ റ (೨ब ࠗ࠙݅ द) @Composable fun TextWrapper(composer: Composer, text: String) { composer.startRestartGroup(-199242123) // ղࠗীࢲ addRecomposeScope() ۽ ܻஹನ࣌ झܳ ୶оೞҊ Text(text = text) composer.endRestartGroup() } -
EPOVUIPMFTLJQQJOH setContent { var number by remember { mutableStateOf(0) }
println("setContent recomposition") Text( modifier = Modifier.clickable { number++ }, text = number.toString() ).also { println("Text recomposition") } } setContent { var number by remember { mutableStateOf(0) } println("setContent recomposition") Button(onClick = { number++ }) { Text( text = number.toString() ).also { println("Text recomposition") } }.also { println("Button recomposition") } } Text RecomposeScope Text RecomposeScope -
EPOVUIPMFTLJQQJOH setContent { var number by remember { mutableStateOf(0) }
println("setContent recomposition") Button(onClick = { number++ }) { Text( text = number.toString() ).also { println("Text recomposition") } }.also { println("Button recomposition") } } Text RecomposeScope Button RecomposeScope -
4UBCJMJUZ4ZTUFN setContent { var number by remember { mutableStateOf(1) }
TextWrapper( modifier = Modifier.clickable { number++ }, text = number.toString() ) } @Composable fun TextWrapper( modifier: Modifier = Modifier, text: String ) { Text(modifier = modifier, text = text) } -
4UBCJMJUZ4ZTUFN setContent { var number by remember { mutableStateOf(1) }
TextWithLambda( modifier = Modifier.clickable { number++ }, text = { number.toString() } ) } @Composable fun TextWithLambda( modifier: Modifier = Modifier, text: () -> String // Function0<String> ) { Text(modifier = modifier, text = text()) } -
NPWBCMF$POUFOU0G val content = remember<@Composable () -> Unit> { {
repeat(2) { Box(modifier = Modifier.size(100.dp).background(color = Color.Green)) } } } Column { Button(onClick = { isRow = !isRow }) { Text(text = "Switch") } if (isRow) { Row { content() } } else { Column { content() } } } -
NPWBCMF$POUFOU0G val content = remember { movableContentOf { // movableContentWithReceiverOf
repeat(2) { Box(modifier = Modifier.size(100.dp).background(color = Color.Green)) } } } Column { Button(onClick = { isRow = !isRow }) { Text(text = "Switch") } if (isRow) { Row { content() } } else { Column { content() } } } -
!3FBE0OMZ$PNQPTBCMF object MaterialTheme { val colors: Colors @Composable @ReadOnlyComposable get()
= LocalColors.current val typography: Typography @Composable @ReadOnlyComposable get() = LocalTypography.current // … } @Composable @ReadOnlyComposable fun stringResource(@StringRes id: Int): String { val resources = resources() return resources.getString(id) } -
!/PO3FTUBSUBCMF$PNQPTBCMF @Composable @NonRestartableComposable fun DisposableEffect(key1: Any?, effect: DisposableEffectScope.() -> DisposableEffectResult)
{ remember(key1) { DisposableEffectImpl(effect) } } @Composable @NonRestartableComposable fun Image( modifier: Modifier = Modifier, colorFilter: ColorFilter? = null, imageVector: ImageVector, contentDescription: String?, alpha: Float = DefaultAlpha, alignment: Alignment = Alignment.Center, contentScale: ContentScale = ContentScale.Fit ) { Image( modifier = modifier, alignment = alignment, contentScale = contentScale, alpha = alpha, colorFilter = colorFilter, painter = rememberVectorPainter(imageVector), contentDescription = contentDescription ) } -
TUBUJD$PNQPTJUJPO-PDBM0G val LocalContext = staticCompositionLocalOf<Context> { noLocalProvidedFor("LocalContext") } val LocalClipboardManager
= staticCompositionLocalOf<ClipboardManager> { noLocalProvidedFor("LocalClipboardManager") } val LocalDensity = staticCompositionLocalOf<Density> { noLocalProvidedFor("LocalDensity") } val LocalFocusManager = staticCompositionLocalOf<FocusManager> { noLocalProvidedFor("LocalFocusManager") } -
#BTFMJOFQSPGJMFT .BDSPCFODINBSLݽٕࢸ ٘ࢿ CBTFMJOFQSPGJMFTࢤࢿ @ExperimentalBaselineProfilesApi @RunWith(AndroidJUnit4::class) class BaselineProfileGenerator {
@get:Rule val baselineProfileRule = BaselineProfileRule() @Test fun startup() = baselineProfileRule.collectBaselineProfile( packageName = AppPackageName ) { pressHome() startActivityAndWait() } } -
#BTFMJOFQSPGJMFT .BDSPCFODINBSLݽٕࢸ ٘ࢿ CBTFMJOFQSPGJMFTਊറஏ @RunWith(AndroidJUnit4::class) class BaselineProfileBenchmark { @get:Rule
val benchmarkRule = MacrobenchmarkRule() // … private fun startup(compilationMode: CompilationMode) { benchmarkRule.measureRepeated( packageName = AppPackageName, metrics = listOf(StartupTimingMetric()), iterations = 10, startupMode = StartupMode.COLD, compilationMode = compilationMode ) { pressHome() startActivityAndWait() } } } -
#BTFMJOFQSPGJMFT .BDSPCFODINBSLݽٕࢸ ٘ࢿ CBTFMJOFQSPGJMFTਊറஏ @RunWith(AndroidJUnit4::class) class BaselineProfileBenchmark { @get:Rule
val benchmarkRule = MacrobenchmarkRule() @Test fun startupNoCompilation() { startup(compilationMode = CompilationMode.None()) // JIT ஹੌ } @Test fun startupBaselineProfile() { startup(compilationMode = CompilationMode.Partial(baselineProfileMode = BaselineProfileMode.Require)) // AOT ஹੌ } // … } -
#BTFMJOFQSPGJMFT ܖӂೠഝࢿച 3VO adb pull CBTFMJOFQSPGUYUਵ۽ੌݺ߸҃റTSDNBJOਵ۽ز ਊറ࠺Ү ਊೡݽٕীઓࢿ୶о dependencies {
implementation("androidx.profileinstaller:profileinstaller:1.2.0-beta01") } -
хࢎפ ஹನૉ ղࠗ ٜ٘ cs.android.com ীࢲ оઉ৳णפ. ۨઃప࣌ীח షझীࢲ
ઁҕೠ షझಕझо ਊغয णפ. QnA🙋