[go: nahoru, domu]

blob: e7e258a52b4d0fad9a06844ad89fa4077df6fb38 [file] [log] [blame]
Qingqing Dengb745a942019-06-05 18:26:52 -07001/*
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
17package androidx.ui.core.selection
18
Chuck Jazdzewskifb6db652019-11-25 08:30:51 -080019import androidx.compose.ambientOf
Siyamed Sinir700df8452019-10-22 20:23:58 -070020
Qingqing Dengb745a942019-06-05 18:26:52 -070021/**
Siyamed Sinir0100f122019-11-16 00:23:12 -080022 * An interface allowing a composable to subscribe and unsubscribe to selection changes.
Qingqing Dengb745a942019-06-05 18:26:52 -070023 */
Qingqing Deng35f97ea2019-09-18 19:24:37 -070024interface SelectionRegistrar {
Siyamed Sinir0100f122019-11-16 00:23:12 -080025 /**
26 * Subscribe to SelectionContainer selection changes.
27 */
28 fun subscribe(selectable: Selectable): Selectable
Qingqing Dengb745a942019-06-05 18:26:52 -070029
Siyamed Sinir0100f122019-11-16 00:23:12 -080030 /**
31 * Unsubscribe from SelectionContainer selection changes.
32 */
33 fun unsubscribe(selectable: Selectable)
Qingqing Deng247f2b42019-12-12 19:48:37 -080034
35 /**
36 * When the Global Position of a subscribed [Selectable] changes, this method
37 * is called.
38 */
39 fun onPositionChange()
Qingqing Dengb745a942019-06-05 18:26:52 -070040}
Siyamed Sinir700df8452019-10-22 20:23:58 -070041
42/**
43 * Ambient of SelectionRegistrar. Composables that implement selection logic can use this ambient
44 * to get a [SelectionRegistrar] in order to subscribe and unsubscribe to [SelectionRegistrar].
45 */
Chuck Jazdzewskifb6db652019-11-25 08:30:51 -080046val SelectionRegistrarAmbient = ambientOf<SelectionRegistrar?>()