Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<3a6a61e2cc2bf01a35ab5c3919462ad5>>
* @generated SignedSource<<c5b83086594762637e8dcad1e0116543>>
*/

/**
Expand Down Expand Up @@ -60,6 +60,12 @@ public object ReactNativeFeatureFlags {
@JvmStatic
public fun deferTextInputTruncationIOS(): Boolean = accessor.deferTextInputTruncationIOS()

/**
* When a TextInput requests no keyboard suggestions (e.g. autoCorrect={false}) on Android, do not apply the default composing-text style (an underline) to text the keyboard is still composing. Styling supplied by the keyboard is kept.
*/
@JvmStatic
public fun disableDefaultComposingTextStyleWithoutSuggestionsAndroid(): Boolean = accessor.disableDefaultComposingTextStyleWithoutSuggestionsAndroid()

/**
* Dispatch view commands in mount item order.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<fe927f4acf804e05b74dbe606e39746f>>
* @generated SignedSource<<c9de82cb6f5b4320048ccbbfe566f13d>>
*/

/**
Expand All @@ -25,6 +25,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
private var cxxNativeAnimatedEnabledCache: Boolean? = null
private var defaultTextToOverflowHiddenCache: Boolean? = null
private var deferTextInputTruncationIOSCache: Boolean? = null
private var disableDefaultComposingTextStyleWithoutSuggestionsAndroidCache: Boolean? = null
private var disableEarlyViewCommandExecutionCache: Boolean? = null
private var disableIdleEventDispatchFrameCallbackRearmAndroidCache: Boolean? = null
private var disableIdleMountItemFrameCallbackRearmAndroidCache: Boolean? = null
Expand Down Expand Up @@ -170,6 +171,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
return cached
}

override fun disableDefaultComposingTextStyleWithoutSuggestionsAndroid(): Boolean {
var cached = disableDefaultComposingTextStyleWithoutSuggestionsAndroidCache
if (cached == null) {
cached = ReactNativeFeatureFlagsCxxInterop.disableDefaultComposingTextStyleWithoutSuggestionsAndroid()
disableDefaultComposingTextStyleWithoutSuggestionsAndroidCache = cached
}
return cached
}

override fun disableEarlyViewCommandExecution(): Boolean {
var cached = disableEarlyViewCommandExecutionCache
if (cached == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<b58702a0f594f409c0d20fd497395fde>>
* @generated SignedSource<<6f7a6d9409eb5948275135351877bf7d>>
*/

/**
Expand Down Expand Up @@ -38,6 +38,8 @@ public object ReactNativeFeatureFlagsCxxInterop {

@DoNotStrip @JvmStatic public external fun deferTextInputTruncationIOS(): Boolean

@DoNotStrip @JvmStatic public external fun disableDefaultComposingTextStyleWithoutSuggestionsAndroid(): Boolean

@DoNotStrip @JvmStatic public external fun disableEarlyViewCommandExecution(): Boolean

@DoNotStrip @JvmStatic public external fun disableIdleEventDispatchFrameCallbackRearmAndroid(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<834b0e9533cbc775a1c12b86140d718d>>
* @generated SignedSource<<53b5e5f6c3730d0f17e079d52474318a>>
*/

/**
Expand Down Expand Up @@ -33,6 +33,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi

override fun deferTextInputTruncationIOS(): Boolean = false

override fun disableDefaultComposingTextStyleWithoutSuggestionsAndroid(): Boolean = false

override fun disableEarlyViewCommandExecution(): Boolean = false

override fun disableIdleEventDispatchFrameCallbackRearmAndroid(): Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<15c65d4497fd9f36f8902efb2812b3b2>>
* @generated SignedSource<<a34475a5b2dceb50777f5b7d42d8769e>>
*/

/**
Expand All @@ -29,6 +29,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
private var cxxNativeAnimatedEnabledCache: Boolean? = null
private var defaultTextToOverflowHiddenCache: Boolean? = null
private var deferTextInputTruncationIOSCache: Boolean? = null
private var disableDefaultComposingTextStyleWithoutSuggestionsAndroidCache: Boolean? = null
private var disableEarlyViewCommandExecutionCache: Boolean? = null
private var disableIdleEventDispatchFrameCallbackRearmAndroidCache: Boolean? = null
private var disableIdleMountItemFrameCallbackRearmAndroidCache: Boolean? = null
Expand Down Expand Up @@ -179,6 +180,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
return cached
}

override fun disableDefaultComposingTextStyleWithoutSuggestionsAndroid(): Boolean {
var cached = disableDefaultComposingTextStyleWithoutSuggestionsAndroidCache
if (cached == null) {
cached = currentProvider.disableDefaultComposingTextStyleWithoutSuggestionsAndroid()
accessedFeatureFlags.add("disableDefaultComposingTextStyleWithoutSuggestionsAndroid")
disableDefaultComposingTextStyleWithoutSuggestionsAndroidCache = cached
}
return cached
}

override fun disableEarlyViewCommandExecution(): Boolean {
var cached = disableEarlyViewCommandExecutionCache
if (cached == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<89f683cb28a7d1ef52c86faa96f1107c>>
* @generated SignedSource<<c07c8441d1f7e4822418103f88fdc327>>
*/

/**
Expand Down Expand Up @@ -33,6 +33,8 @@ public interface ReactNativeFeatureFlagsProvider {

@DoNotStrip public fun deferTextInputTruncationIOS(): Boolean

@DoNotStrip public fun disableDefaultComposingTextStyleWithoutSuggestionsAndroid(): Boolean

@DoNotStrip public fun disableEarlyViewCommandExecution(): Boolean

@DoNotStrip public fun disableIdleEventDispatchFrameCallbackRearmAndroid(): Boolean
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.views.textinput

import android.os.Build
import android.text.Spannable
import android.text.SpannableString
import android.text.Spanned
import android.text.style.CharacterStyle
import android.view.inputmethod.InputConnection
import android.view.inputmethod.InputConnectionWrapper
import android.view.inputmethod.TextAttribute
import androidx.annotation.RequiresApi

/**
* Keeps [android.view.inputmethod.BaseInputConnection] from applying the theme's default composing
* style (`android:candidatesTextStyleSpans`, an underline by default) to composing text. Styling
* supplied by the IME is kept.
*/
internal class NoDefaultComposingStyleInputConnectionWrapper(
target: InputConnection,
private val editText: ReactEditText,
) : InputConnectionWrapper(target, false) {

override fun setComposingText(text: CharSequence, newCursorPosition: Int): Boolean =
super.setComposingText(asSpannable(text), newCursorPosition)

@RequiresApi(Build.VERSION_CODES.TIRAMISU)
override fun setComposingText(
text: CharSequence,
newCursorPosition: Int,
textAttribute: TextAttribute?,
): Boolean = super.setComposingText(asSpannable(text), newCursorPosition, textAttribute)

override fun setComposingRegion(start: Int, end: Int): Boolean {
val consumed = super.setComposingRegion(start, end)
removeDefaultComposingStyle()
return consumed
}

@RequiresApi(Build.VERSION_CODES.TIRAMISU)
override fun setComposingRegion(start: Int, end: Int, textAttribute: TextAttribute?): Boolean {
val consumed = super.setComposingRegion(start, end, textAttribute)
removeDefaultComposingStyle()
return consumed
}

// The default style is only added to composing text that is not already Spannable.
private fun asSpannable(text: CharSequence): CharSequence =
text as? Spannable ?: SpannableString(text)

// setComposingRegion clears every composing span and then applies only the default style, so any
// composing CharacterStyle left in the region is the default one.
private fun removeDefaultComposingStyle() {
val text = editText.text ?: return
for (span in text.getSpans(0, text.length, CharacterStyle::class.java)) {
if ((text.getSpanFlags(span) and Spanned.SPAN_COMPOSING) != 0) {
text.removeSpan(span)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,13 @@ public open class ReactEditText public constructor(context: Context) : AppCompat
checkNotNull(eventDispatcher),
)
}
if (
inputConnection != null &&
(inputType and InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS) != 0 &&
ReactNativeFeatureFlags.disableDefaultComposingTextStyleWithoutSuggestionsAndroid()
) {
inputConnection = NoDefaultComposingStyleInputConnectionWrapper(inputConnection, this)
}

if (isMultiline && (shouldBlurOnReturn() || shouldSubmitOnReturn())) {
// Remove IME_FLAG_NO_ENTER_ACTION to keep the original IME_OPTION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<407c8e5915db07bb6cc2b9ba4449750a>>
* @generated SignedSource<<b471103e6a0bb20855625e6901f8b261>>
*/

/**
Expand Down Expand Up @@ -69,6 +69,12 @@ class ReactNativeFeatureFlagsJavaProvider
return method(javaProvider_);
}

bool disableDefaultComposingTextStyleWithoutSuggestionsAndroid() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("disableDefaultComposingTextStyleWithoutSuggestionsAndroid");
return method(javaProvider_);
}

bool disableEarlyViewCommandExecution() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("disableEarlyViewCommandExecution");
Expand Down Expand Up @@ -692,6 +698,11 @@ bool JReactNativeFeatureFlagsCxxInterop::deferTextInputTruncationIOS(
return ReactNativeFeatureFlags::deferTextInputTruncationIOS();
}

bool JReactNativeFeatureFlagsCxxInterop::disableDefaultComposingTextStyleWithoutSuggestionsAndroid(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::disableDefaultComposingTextStyleWithoutSuggestionsAndroid();
}

bool JReactNativeFeatureFlagsCxxInterop::disableEarlyViewCommandExecution(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::disableEarlyViewCommandExecution();
Expand Down Expand Up @@ -1233,6 +1244,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
makeNativeMethod(
"deferTextInputTruncationIOS",
JReactNativeFeatureFlagsCxxInterop::deferTextInputTruncationIOS),
makeNativeMethod(
"disableDefaultComposingTextStyleWithoutSuggestionsAndroid",
JReactNativeFeatureFlagsCxxInterop::disableDefaultComposingTextStyleWithoutSuggestionsAndroid),
makeNativeMethod(
"disableEarlyViewCommandExecution",
JReactNativeFeatureFlagsCxxInterop::disableEarlyViewCommandExecution),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<7cb5d49e9124d56b3e242e2023db8649>>
* @generated SignedSource<<3c61dcb890c85e67c13902559d9e03da>>
*/

/**
Expand Down Expand Up @@ -45,6 +45,9 @@ class JReactNativeFeatureFlagsCxxInterop
static bool deferTextInputTruncationIOS(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static bool disableDefaultComposingTextStyleWithoutSuggestionsAndroid(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static bool disableEarlyViewCommandExecution(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

Expand Down
Loading
Loading