1 /*
2  * Copyright 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package androidx.compose.ui.node
18 
19 import androidx.compose.ui.layout.LayoutCoordinates
20 import androidx.compose.ui.layout.LayoutModifier
21 import androidx.compose.ui.layout.onSizeChanged
22 import androidx.compose.ui.unit.IntSize
23 
24 /**
25  * A [androidx.compose.ui.Modifier.Node] which receives various callbacks in response to local
26  * changes in layout.
27  *
28  * This is the [androidx.compose.ui.Modifier.Node] equivalent of
29  * [androidx.compose.ui.layout.OnRemeasuredModifier] and
30  * [androidx.compose.ui.layout.OnPlacedModifier]
31  *
32  * Example usage:
33  *
34  * @sample androidx.compose.ui.samples.OnSizeChangedSample
35  * @sample androidx.compose.ui.samples.OnPlaced
36  * @sample androidx.compose.ui.samples.LayoutAwareModifierNodeSample
37  */
38 interface LayoutAwareModifierNode : DelegatableNode {
39     /**
40      * [onPlaced] is called after the parent [LayoutModifier] and parent layout has been placed and
41      * before child [LayoutModifier] is placed. This allows child [LayoutModifier] to adjust its own
42      * placement based on where the parent is.
43      *
44      * If you only need to access the current [LayoutCoordinates] at a single point in time from
45      * outside this method, use [currentLayoutCoordinates].
46      */
onPlacednull47     fun onPlaced(coordinates: LayoutCoordinates) {}
48 
49     /**
50      * This method is called when the layout content is remeasured. The most common usage is
51      * [onSizeChanged].
52      */
onRemeasurednull53     fun onRemeasured(size: IntSize) {}
54 }
55 
56 // TODO(b/309776096): Make it public
57 internal interface OnUnplacedModifierNode : DelegatableNode {
onUnplacednull58     fun onUnplaced()
59 }
60