Skip to content

Commit

Permalink
Apply Spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
bentrengrove authored and github-actions[bot] committed Nov 20, 2023
1 parent 31595c1 commit ea58b23
Showing 1 changed file with 35 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.compose.snippets.modifiers

import android.annotation.SuppressLint
Expand All @@ -17,7 +33,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.drawscope.ContentDrawScope
Expand Down Expand Up @@ -75,7 +90,6 @@ fun Modifier.fadedBackground(): Modifier {
}
// [END android_compose_custom_modifiers_4]


private object CustomModifierSnippets5 {
// [START android_compose_custom_modifiers_5]
@Composable
Expand All @@ -101,7 +115,6 @@ private object CustomModifierSnippets5 {
// [END android_compose_custom_modifiers_5]
}


// [START android_compose_custom_modifiers_6]
val extractedModifier = Modifier.background(Color.Red) // Hoisted to save allocations

Expand Down Expand Up @@ -142,7 +155,6 @@ private data class CircleElement(val color: Color) : ModifierNodeElement<CircleN
fun Modifier.circle(color: Color) = this then CircleElement(color)
// [END android_compose_custom_modifiers_9]


private object CustomModifierSnippets10 {
// [START android_compose_custom_modifiers_10]
// Modifier factory
Expand All @@ -169,7 +181,7 @@ private object CustomModifierSnippets10 {
// [START android_compose_custom_modifiers_11]
fun Modifier.fixedPadding() = this then FixedPaddingElement

data object FixedPaddingElement: ModifierNodeElement<FixedPaddingNode>() {
data object FixedPaddingElement : ModifierNodeElement<FixedPaddingNode>() {
override fun create() = FixedPaddingNode()
override fun update(node: FixedPaddingNode) {}
}
Expand Down Expand Up @@ -197,7 +209,9 @@ class FixedPaddingNode : LayoutModifierNode, Modifier.Node() {
// [END android_compose_custom_modifiers_11]

// [START android_compose_custom_modifiers_12]
class BackgroundColorConsumerNode : Modifier.Node(), DrawModifierNode,
class BackgroundColorConsumerNode :
Modifier.Node(),
DrawModifierNode,
CompositionLocalConsumerModifierNode {
override fun ContentDrawScope.draw() {
val currentColor = currentValueOf(LocalContentColor)
Expand All @@ -207,16 +221,18 @@ class BackgroundColorConsumerNode : Modifier.Node(), DrawModifierNode,
}
// [END android_compose_custom_modifiers_12]

private object UnityDensity: Density {
private object UnityDensity : Density {
override val density: Float
get() = 1f
override val fontScale: Float
get() = 1f
}
data class DefaultFlingBehavior(var flingDecay: DecayAnimationSpec<Density>)
// [START android_compose_custom_modifiers_13]
class ScrollableNode : Modifier.Node(),
ObserverModifierNode, CompositionLocalConsumerModifierNode {
class ScrollableNode :
Modifier.Node(),
ObserverModifierNode,
CompositionLocalConsumerModifierNode {

// Place holder fling behavior, we'll initialize it when the density is available.
val defaultFlingBehavior = DefaultFlingBehavior(splineBasedDecay(UnityDensity))
Expand All @@ -240,7 +256,7 @@ class ScrollableNode : Modifier.Node(),

object CustomModifierSnippets14 {
// [START android_compose_custom_modifiers_14]
class CircleNode(var color: Color): Modifier.Node(), DrawModifierNode {
class CircleNode(var color: Color) : Modifier.Node(), DrawModifierNode {
private val alpha = Animatable(1f)

override fun ContentDrawScope.draw() {
Expand All @@ -250,8 +266,10 @@ object CustomModifierSnippets14 {

override fun onAttach() {
coroutineScope.launch {
alpha.animateTo(0f,
infiniteRepeatable(tween(1000), RepeatMode.Reverse)) {
alpha.animateTo(
0f,
infiniteRepeatable(tween(1000), RepeatMode.Reverse)
) {
}
}
}
Expand All @@ -260,16 +278,16 @@ object CustomModifierSnippets14 {
}

class InteractionData
class FocusableNode(val interactionData: InteractionData): DelegatableNode {
class FocusableNode(val interactionData: InteractionData) : DelegatableNode {
override val node: Modifier.Node
get() = TODO("Not yet implemented")
}
class IndicationNode(val interactionData: InteractionData): DelegatableNode {
class IndicationNode(val interactionData: InteractionData) : DelegatableNode {
override val node: Modifier.Node
get() = TODO("Not yet implemented")
}
// [START android_compose_custom_modifiers_15]
class ClickableNode: DelegatingNode() {
class ClickableNode : DelegatingNode() {
val interactionData = InteractionData()
val focusableNode = delegate(
FocusableNode(interactionData)
Expand All @@ -280,7 +298,7 @@ class ClickableNode: DelegatingNode() {
}
// [END android_compose_custom_modifiers_15]

class ClickablePointerInputNode(var onClick: () -> Unit): Modifier.Node(), DelegatableNode {
class ClickablePointerInputNode(var onClick: () -> Unit) : Modifier.Node(), DelegatableNode {
fun update(onClick: () -> Unit) {
this.onClick = onClick
}
Expand All @@ -290,7 +308,7 @@ class SampleInvalidatingNode(
var color: Color,
var size: IntSize,
var onClick: () -> Unit
): DelegatingNode(), LayoutModifierNode, DrawModifierNode {
) : DelegatingNode(), LayoutModifierNode, DrawModifierNode {
override val shouldAutoInvalidate: Boolean
get() = false

Expand Down

0 comments on commit ea58b23

Please sign in to comment.