From d63c9997a8b95a0f59f01586a2676bb2124390a9 Mon Sep 17 00:00:00 2001 From: Melissa Vallee Date: Tue, 15 Sep 2026 22:26:47 -0400 Subject: [PATCH 01/17] fix: animate focused teardown and refine iOS accent selection --- README.md | 4 ++ .../main/java/com/keyflow/KeyflowInputView.kt | 22 ++++-- docs/api.md | 1 + example/src/App.tsx | 7 ++ example/src/screens/CustomFontScreen.tsx | 2 +- example/src/screens/LongPressScreen.tsx | 2 +- example/src/screens/ProductThemeScreen.tsx | 2 +- example/src/screens/ShowcaseScreen.tsx | 10 +++ example/src/screens/TeardownScreen.tsx | 71 +++++++++++++++++++ example/src/screens/TransparencyScreen.tsx | 2 +- ios/KeyflowCursorNavigator.swift | 7 ++ ios/KeyflowInputView.swift | 7 +- ios/KeyflowKey.swift | 7 +- ios/KeyflowKeyboardView.swift | 11 ++- scripts/android-tests/app.py | 23 +++++- scripts/android-tests/test_app.py | 13 ++-- scripts/ci/run-ios.sh | 2 +- scripts/ci/workflow.test.mjs | 8 ++- scripts/ios-tests/KeyflowQwertyTests.swift | 42 +++++++++-- scripts/ios-tests/KeyflowRenderingTests.swift | 63 +++++++++++++++- src/__tests__/useKeyflow.test.ts | 39 ++++++++++ src/useKeyflow.ts | 21 +++++- 22 files changed, 330 insertions(+), 36 deletions(-) create mode 100644 example/src/screens/TeardownScreen.tsx diff --git a/README.md b/README.md index de073c9..ed553e9 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,8 @@ export function Composer() { On iOS, hold space to enter trackpad mode, then slide in any direction. A floating caret follows the finger freely across letters and blank space inside the input. On release, it snaps to the nearest valid insertion position, including wrapped lines. Android's space-slide gesture supports both directions too. The drag target stays independent of the snapped caret, so short lines do not discard its horizontal position. Return follows your input's React Native `submitBehavior`; multiline inputs insert a newline by default. +For automatic focus, pass `autoFocus: true` to `useKeyflow()` instead of setting it on `TextInput`. Keyflow waits for native attachment before presenting the input. + The hook also exposes stable `focus()` and `blur()` methods. They safely do nothing while the input is unmounted. `inputRef` remains available for other native input methods: ```tsx @@ -175,6 +177,8 @@ const { keyflowInputProps } = useKeyflow({ Sections support colors, pressed colors, borders, corner radius, fonts, and icon sizing where applicable. `color` supplies the icon and pressed foreground unless explicitly overridden. If you set `iconColor`, remember to give selected states a contrasting icon color too. +On iOS, the long-press accent popup and its choices omit borders. The selected accent uses the regular keys’ corner radius. + The API is shared across phone, tablet, portrait and landscape. Native layout determines the key geometry; customization does not define new rows or touch targets. [Full theme options and limits](docs/api.md#theme-reference). ### Transparent panel, transparent keys—or both diff --git a/android/src/main/java/com/keyflow/KeyflowInputView.kt b/android/src/main/java/com/keyflow/KeyflowInputView.kt index 951f74f..bf3deaf 100644 --- a/android/src/main/java/com/keyflow/KeyflowInputView.kt +++ b/android/src/main/java/com/keyflow/KeyflowInputView.kt @@ -198,10 +198,11 @@ class KeyflowInputView(context: Context, private val expoContext: AppContext) : if (changed && field.hasFocus()) requestKeyboard() } - private fun detachInput() { + private fun detachInput(animated: Boolean = false, resigningFocus: Boolean = false) { val field = attachedEditor ?: return removeCallbacks(showRequest) - hideKeyboard(animated = false) + if (resigningFocus) field.clearFocus() + hideKeyboard(animated = animated) field.removeTextChangedListener(providedTextWatcher) softInputPolicy.restore(field) attachedEditor = null @@ -217,6 +218,7 @@ class KeyflowInputView(context: Context, private val expoContext: AppContext) : private val keyboard = KeyflowKeyboardView(context) { action, text -> activate(action, text) } private var popup: PopupWindow? = null private var navigationScrim: ColorDrawable? = null + private var navigationScrimHost: View? = null private var previousLightNavigation: Boolean? = null private fun updateNavigationScrim() { @@ -228,6 +230,7 @@ class KeyflowInputView(context: Context, private val expoContext: AppContext) : navigationScrim ?: ColorDrawable().also { navigationScrim = it + navigationScrimHost = rootView rootView.overlay.add(it) previousLightNavigation = ViewCompat.getWindowInsetsController(rootView)?.isAppearanceLightNavigationBars @@ -240,12 +243,14 @@ class KeyflowInputView(context: Context, private val expoContext: AppContext) : } private fun clearNavigationScrim() { - navigationScrim?.let { rootView.overlay.remove(it) } + val host = navigationScrimHost ?: rootView + navigationScrim?.let { host.overlay.remove(it) } navigationScrim = null previousLightNavigation?.let { - ViewCompat.getWindowInsetsController(rootView)?.isAppearanceLightNavigationBars = it + ViewCompat.getWindowInsetsController(host)?.isAppearanceLightNavigationBars = it } previousLightNavigation = null + navigationScrimHost = null } private var lastSpace = 0L @@ -468,15 +473,18 @@ class KeyflowInputView(context: Context, private val expoContext: AppContext) : handoffHeight = 0f viewTreeObserver.removeOnGlobalLayoutListener(globalLayout) viewTreeObserver.removeOnGlobalFocusChangeListener(providedFocusListener) - detachInput() + val animated = navigationScrimHost?.isAttachedToWindow == true + detachInput(animated = animated, resigningFocus = true) ViewCompat.setWindowInsetsAnimationCallback(this, null) ViewCompat.setOnApplyWindowInsetsListener(this, null) - hideKeyboard(animated = false) + hideKeyboard(animated = animated) super.onDetachedFromWindow() } fun cleanup() { - detachInput() + onKeyflowHeightChange = null + onKeyflowFrameChange = null + detachInput(animated = navigationScrimHost?.isAttachedToWindow == true, resigningFocus = true) (parent as? ViewGroup)?.removeView(this) } diff --git a/docs/api.md b/docs/api.md index cb2c283..cf257c7 100644 --- a/docs/api.md +++ b/docs/api.md @@ -75,6 +75,7 @@ export function Input() { | Option | Behavior | | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | +| `autoFocus` | Focuses after native attachment; defaults to `false`. Use instead of TextInput’s `autoFocus` prop. | | `enabled` | Enables native attachment; defaults to `true` | | `keyboardMode` | `custom` (default) or `system` | | `keyboardAppearance` | `light` or `dark`; otherwise follows device appearance | diff --git a/example/src/App.tsx b/example/src/App.tsx index b0fa390..10cfc96 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -14,7 +14,9 @@ import { LanguageScreen } from './screens/LanguageScreen'; import { LayoutsScreen } from './screens/LayoutsScreen'; import { InteractionScreen } from './screens/InteractionScreen'; import { LongPressScreen } from './screens/LongPressScreen'; +import { TeardownScreen } from './screens/TeardownScreen'; export type Routes = { + Teardown: undefined; Showcase: undefined; Transparency: undefined; Interactions: undefined; @@ -82,6 +84,11 @@ export default function App() { component={InteractionScreen} options={{ title: 'Native interaction tests' }} /> + void }) { + const { keyflowInputProps } = useKeyflow({ + autoFocus: true, + keyflowTheme: studioTheme, + }); + return ( + + +