1 /* 2 * Copyright 2024 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.foundation 18 19 import androidx.compose.foundation.gestures.detectTapAndPress 20 import androidx.compose.foundation.gestures.detectTapGestures 21 import kotlin.jvm.JvmField 22 23 /** 24 * This is a collection of flags which are used to guard against regressions in some of the 25 * "riskier" refactors or new feature support that is added to this module. These flags are always 26 * "on" in the published artifact of this module, however these flags allow end consumers of this 27 * module to toggle them "off" in case this new path is causing a regression. 28 * 29 * These flags are considered temporary, and there should be no expectation for these flags be 30 * around for an extended period of time. If you have a regression that one of these flags fixes, it 31 * is strongly encouraged for you to file a bug ASAP. 32 * 33 * **Usage:** 34 * 35 * In order to turn a feature off in a debug environment, it is recommended to set this to false in 36 * as close to the initial loading of the application as possible. Changing this value after compose 37 * library code has already been loaded can result in undefined behavior. 38 * 39 * class MyApplication : Application() { 40 * override fun onCreate() { 41 * ComposeFoundationFlags.SomeFeatureEnabled = false 42 * super.onCreate() 43 * } 44 * } 45 * 46 * In order to turn this off in a release environment, it is recommended to additionally utilize R8 47 * rules which force a single value for the entire build artifact. This can result in the new code 48 * paths being completely removed from the artifact, which can often have nontrivial positive 49 * performance impact. 50 * 51 * -assumevalues class androidx.compose.runtime.ComposeFoundationFlags { 52 * public static boolean SomeFeatureEnabled return false 53 * } 54 */ 55 @ExperimentalFoundationApi 56 object ComposeFoundationFlags { 57 /** 58 * Selecting flag to enable Drag Gesture "Pick-up" on drag gesture detectors. This also applies 59 * to Draggables and Scrollables which use gesture detectors as well. Any parent drag detector 60 * will continue to monitor the event stream until the gesture terminates (all pointers are 61 * lifted), if a child gives up an event, the parent gesture detector will "pick-up" and 62 * continue the gesture until all pointers are up. 63 */ 64 @Suppress("MutableBareField") @JvmField var DragGesturePickUpEnabled = true 65 66 /** 67 * Whether to use more immediate coroutine dispatching in [detectTapGestures] and 68 * [detectTapAndPress], true by default. 69 */ 70 @Suppress("MutableBareField") 71 @JvmField 72 var isDetectTapGesturesImmediateCoroutineDispatchEnabled = true 73 74 /** 75 * Whether to use the new context menu API and default implementations in 76 * [SelectionContainer][androidx.compose.foundation.text.selection.SelectionContainer], and all 77 * [BasicTextField][androidx.compose.foundation.text.BasicTextField]s. If false, the previous 78 * context menu that has no public APIs will be used instead. 79 */ 80 // TODO(grantapher-cm-api-publicize) Make field public 81 @Suppress("MutableBareField") @JvmField internal var isNewContextMenuEnabled = false 82 83 /** 84 * Selecting flag to enable the use of new PausableComposition in lazy layout prefetch. This 85 * change allows us to distribute work we need to do during the prefetch better, for example we 86 * can only perform the composition for parts of the LazyColumn's next item during one ui frame, 87 * and then continue composing the rest of it in the next frames. 88 */ 89 @Suppress("MutableBareField") @JvmField var isPausableCompositionInPrefetchEnabled = false 90 91 /** 92 * Selecting flag to enable the use of automatic nested prefetch. When this is enabled, nested 93 * prefetching using the default Prefetch Strategies 94 * [androidx.compose.foundation.lazy.LazyListPrefetchStrategy] and 95 * [androidx.compose.foundation.lazy.grid.LazyGridPrefetchStrategy] or Cache Window will be 96 * automatically defined by the number of visible items in the nested LazyLayout. 97 */ 98 @Suppress("MutableBareField") @JvmField var isAutomaticNestedPrefetchEnabled = true 99 100 /** 101 * Flag that enables an optimized implementation for the [clickable] overload without an 102 * [Indication] parameter. This also applies to [combinedClickable], 103 * [androidx.compose.foundation.selection.selectable], and 104 * [androidx.compose.foundation.selection.toggleable], which also use [clickable]. When this 105 * flag is true, [clickable] will no longer use [androidx.compose.ui.composed], which leads to 106 * improved performance and allows for composables with a [clickable] modifier to skip. However, 107 * this means that only [IndicationNodeFactory] instances can be supported - if a 108 * non-[IndicationNodeFactory] instance is provided to [LocalIndication], [clickable] will crash 109 * at runtime. To resolve this either migrate the [Indication] implementation used to a 110 * [IndicationNodeFactory], or use the other [clickable] overload with an explicit [Indication] 111 * parameter - this flag can be disabled as a temporary migration aid. 112 */ 113 @Suppress("MutableBareField") @JvmField var isNonComposedClickableEnabled = true 114 115 /** 116 * Enables Compose trigger for calling 117 * [androidx.compose.ui.node.DelegatableNode.dispatchOnScrollChanged] callbacks during scroll 118 * events. 119 */ 120 @Suppress("MutableBareField") @JvmField var isOnScrollChangedCallbackEnabled: Boolean = true 121 } 122