Qingqing Deng | b745a94 | 2019-06-05 18:26:52 -0700 | [diff] [blame] | 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.ui.core.selection |
| 18 | |
Chuck Jazdzewski | fb6db65 | 2019-11-25 08:30:51 -0800 | [diff] [blame] | 19 | import androidx.compose.ambientOf |
Siyamed Sinir | 700df845 | 2019-10-22 20:23:58 -0700 | [diff] [blame] | 20 | |
Qingqing Deng | b745a94 | 2019-06-05 18:26:52 -0700 | [diff] [blame] | 21 | /** |
Siyamed Sinir | 0100f12 | 2019-11-16 00:23:12 -0800 | [diff] [blame] | 22 | * An interface allowing a composable to subscribe and unsubscribe to selection changes. |
Qingqing Deng | b745a94 | 2019-06-05 18:26:52 -0700 | [diff] [blame] | 23 | */ |
Qingqing Deng | 35f97ea | 2019-09-18 19:24:37 -0700 | [diff] [blame] | 24 | interface SelectionRegistrar { |
Siyamed Sinir | 0100f12 | 2019-11-16 00:23:12 -0800 | [diff] [blame] | 25 | /** |
| 26 | * Subscribe to SelectionContainer selection changes. |
| 27 | */ |
| 28 | fun subscribe(selectable: Selectable): Selectable |
Qingqing Deng | b745a94 | 2019-06-05 18:26:52 -0700 | [diff] [blame] | 29 | |
Siyamed Sinir | 0100f12 | 2019-11-16 00:23:12 -0800 | [diff] [blame] | 30 | /** |
| 31 | * Unsubscribe from SelectionContainer selection changes. |
| 32 | */ |
| 33 | fun unsubscribe(selectable: Selectable) |
Qingqing Deng | 247f2b4 | 2019-12-12 19:48:37 -0800 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * When the Global Position of a subscribed [Selectable] changes, this method |
| 37 | * is called. |
| 38 | */ |
| 39 | fun onPositionChange() |
Qingqing Deng | b745a94 | 2019-06-05 18:26:52 -0700 | [diff] [blame] | 40 | } |
Siyamed Sinir | 700df845 | 2019-10-22 20:23:58 -0700 | [diff] [blame] | 41 | |
| 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 Jazdzewski | fb6db65 | 2019-11-25 08:30:51 -0800 | [diff] [blame] | 46 | val SelectionRegistrarAmbient = ambientOf<SelectionRegistrar?>() |