1 /*
2  * Copyright 2019 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.autofill
18 
19 /**
20  * The autofill tree is a temporary data structure that is used before the Semantics Tree is
21  * implemented. This data structure is used by compose components to set autofill hints (via
22  * [AutofillNode]s). It is also used by the autofill framework to communicate with Compose
23  * components (by calling [performAutofill]).
24  *
25  * The [AutofillTree] will be replaced by Autofill Semantics (b/138604305).
26  *
27  * Since this is a temporary implementation, it is implemented as a list of [children], which is
28  * essentially a tree of height = 1
29  */
30 @Deprecated(
31     """
32         Use the new semantics-based Autofill APIs androidx.compose.ui.autofill.ContentType and
33         androidx.compose.ui.autofill.ContentDataType instead.
34         """
35 )
36 class AutofillTree {
37     /** A map which contains [AutofillNode]s, where every node represents an autofill-able field. */
38     val children: MutableMap<Int, @Suppress("Deprecation") AutofillNode> = mutableMapOf()
39 
40     /** Add the specified [AutofillNode] to the [AutofillTree]. */
plusAssignnull41     operator fun plusAssign(autofillNode: @Suppress("Deprecation") AutofillNode) {
42         children[autofillNode.id] = autofillNode
43     }
44 
45     /**
46      * The autofill framework uses this function to 'fill' the [AutofillNode] represented by [id]
47      * with the specified [value].
48      */
performAutofillnull49     fun performAutofill(id: Int, value: String) = children[id]?.onFill?.invoke(value)
50 }
51