diff --git a/README.md b/README.md index de073c9..ed72f57 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 @@ -157,6 +159,7 @@ export const keyflowTheme = { const { keyflowInputProps } = useKeyflow({ keyflowTheme, + returnKeyContent: { icon: 'send' }, }); ; @@ -175,6 +178,52 @@ 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. +Set the custom return key to app-owned text or a portable native icon: + +```tsx +const { keyflowInputProps } = useKeyflow({ + returnKeyContent: { icon: 'send' }, +}); + +; +``` + +Use `{ text: 'Post' }` for app-owned text. Available icons are `return`, `arrow-right`, `checkmark`, `send`, and `search`. This changes only Keyflow's presentation; use the `TextInput`'s `submitBehavior` and `onSubmitEditing` for behavior. A multiline input with `submitBehavior="newline"` inserts `\n`. + +For example, these two multiline inputs display different return keys and keep their normal React Native behavior: + +```tsx +const { keyflowInputProps: sendInputProps } = useKeyflow({ + returnKeyContent: { icon: 'send' }, +}); +const { keyflowInputProps: newlineInputProps } = useKeyflow({ + returnKeyContent: { text: 'New line' }, +}); + +// Displays a send icon and calls sendMessage. + + +// Displays “New line” and inserts a newline. + +``` + +The example app has an interactive **Behavior → Return key actions** screen for testing both cases. + +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 @@ -278,8 +327,8 @@ Watch the MP4s: [iPhone transitions](docs/media/ios-transitions.mp4) · [Android - - + +
iPhone · Hold and slide between accentsAndroid phone · Hold and slide between accents
Slide between iPhone accent choices with Story Studio’s rose selection highlightAndroid accent highlight following a continuous drag across accent choicesStory Studio on iPhone opening the accent row, sliding its rose focus, and committing the focused accentStory Studio on Android opening the accent grid, sliding its rose focus across both rows, and committing the focused accent
@@ -328,14 +377,14 @@ Need the user’s actual keyboard and its full feature set? Pass `keyboardMode: ## Example app -| Category | Explore | -| ----------- | ---------------------------------------------------------------------- | -| Behavior | Typing, long presses, deletion, cursor movement and native comparisons | -| Multiline | Notes with paragraphs, wrapped lines, Return and movement on both axes | -| Transitions | Presentation, dismissal, mode handoffs and keyboard avoidance | -| Layouts | Number pads, rotation, English/French switching | -| Appearance | Fonts, borders, sizes, focused accents and customization bounds | -| Showcases | Platform defaults, Story Studio, Quicksand and transparency | +| Category | Explore | +| ----------- | ---------------------------------------------------------------------------- | +| Behavior | Typing, long presses, return actions, cursor movement and native comparisons | +| Multiline | Notes with paragraphs, wrapped lines, Return and movement on both axes | +| Transitions | Presentation, dismissal, mode handoffs and keyboard avoidance | +| Layouts | Number pads, rotation, English/French switching | +| Appearance | Fonts, borders, sizes, focused accents and customization bounds | +| Showcases | Platform defaults, Story Studio, Quicksand and transparency | The example source lives in [`example/`](example). `corepack yarn example:export` also prepares a standalone example repository under `artifacts/keyflow-example-repo` with a bundled library package. diff --git a/android/src/androidTest/java/com/keyflow/KeyflowRenderingTest.kt b/android/src/androidTest/java/com/keyflow/KeyflowRenderingTest.kt index 516258b..cfffbe6 100644 --- a/android/src/androidTest/java/com/keyflow/KeyflowRenderingTest.kt +++ b/android/src/androidTest/java/com/keyflow/KeyflowRenderingTest.kt @@ -1,7 +1,10 @@ package com.keyflow +import android.view.KeyEvent import android.view.MotionEvent import android.view.View +import android.view.inputmethod.EditorInfo +import android.widget.EditText import androidx.test.core.app.ActivityScenario import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.runners.AndroidJUnit4 @@ -13,6 +16,41 @@ import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) class KeyflowRenderingTest { + @Test + fun returnActionLetsReactNativeChooseSubmitOrNewline() { + ActivityScenario.launch(KeyflowTestActivity::class.java).use { scenario -> + scenario.onActivity { activity -> + val singleLine = ReturnTrackingEditText(activity) + singleLine.setSingleLine(true) + dispatchKeyflowSubmit(singleLine) + assertEquals(listOf(EditorInfo.IME_ACTION_DONE), singleLine.editorActions) + assertTrue(singleLine.keyEvents.isEmpty()) + + val multiline = ReturnTrackingEditText(activity) + multiline.setSingleLine(false) + dispatchKeyflowSubmit(multiline) + assertTrue(multiline.editorActions.isEmpty()) + assertEquals( + listOf(KeyEvent.ACTION_DOWN, KeyEvent.ACTION_UP), + multiline.keyEvents.map { it.action }, + ) + assertTrue(multiline.keyEvents.all { it.keyCode == KeyEvent.KEYCODE_ENTER }) + } + } + } + + @Test + fun returnKeySupportsCustomText() = withKeyboard { activity, keys -> + activity.keyboard.theme = + KeyflowTheme( + JSONObject().apply { put("returnKeyContent", JSONObject().apply { put("text", "Send") }) } + ) + val submit = keys().first { it.action == "submit" } + assertEquals("Send", submit.label) + assertEquals("Send", submit.text.toString()) + assertEquals("Send", submit.contentDescription) + } + @Test fun reactOwnedSoftInputFlagSurvivesModeChangesAndDetach() { ActivityScenario.launch(KeyflowTestActivity::class.java).use { scenario -> @@ -305,3 +343,17 @@ class KeyflowRenderingTest { keyboard.layout(0, 0, keyboard.measuredWidth, keyboard.measuredHeight) } } + +private class ReturnTrackingEditText(context: android.content.Context) : EditText(context) { + val editorActions = mutableListOf() + val keyEvents = mutableListOf() + + override fun onEditorAction(actionCode: Int) { + editorActions += actionCode + } + + override fun dispatchKeyEvent(event: KeyEvent): Boolean { + keyEvents += event + return true + } +} diff --git a/android/src/main/java/com/keyflow/KeyflowIcons.kt b/android/src/main/java/com/keyflow/KeyflowIcons.kt index 889b625..b7ff334 100644 --- a/android/src/main/java/com/keyflow/KeyflowIcons.kt +++ b/android/src/main/java/com/keyflow/KeyflowIcons.kt @@ -79,6 +79,20 @@ internal object KeyflowIcons { path(18f, 9f, 12f, 15f) } "submit" -> path(4f, 12f, 9f, 17f, 20f, 6f) + "return" -> path(20f, 5f, 20f, 12f, 7f, 12f, 11f, 8f, 7f, 12f, 11f, 16f) + "arrow-right" -> { + path(4f, 12f, 20f, 12f) + path(14f, 6f, 20f, 12f, 14f, 18f) + } + "checkmark" -> path(4f, 12f, 9f, 17f, 20f, 6f) + "send" -> { + path(3f, 4f, 21f, 12f, 3f, 20f, 7f, 12f, close = true) + path(7f, 12f, 21f, 12f) + } + "search" -> { + canvas.drawCircle(10f, 10f, 6f, p) + path(14.5f, 14.5f, 20f, 20f) + } "paste" -> { canvas.drawRoundRect(RectF(5f, 4f, 19f, 22f), 1f, 1f, p) canvas.drawRoundRect(RectF(9f, 2f, 15f, 6f), 1f, 1f, p) diff --git a/android/src/main/java/com/keyflow/KeyflowInputView.kt b/android/src/main/java/com/keyflow/KeyflowInputView.kt index 951f74f..b9885e7 100644 --- a/android/src/main/java/com/keyflow/KeyflowInputView.kt +++ b/android/src/main/java/com/keyflow/KeyflowInputView.kt @@ -195,13 +195,16 @@ class KeyflowInputView(context: Context, private val expoContext: AppContext) : } softInputPolicy.apply(field, mode == "system") updateInputContext() - if (changed && field.hasFocus()) requestKeyboard() + // Refocusing an already-focused editor does not emit another focus change. + // Attachment is also used by the hook's focus(), so restore its panel here. + if (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 +220,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 +232,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 +245,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 +475,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) } @@ -572,22 +582,7 @@ class KeyflowInputView(context: Context, private val expoContext: AppContext) : } private fun submit() { - // Keep React Native's submitBehavior and onSubmitEditing event pipeline. - if (editor.inputType and android.text.InputType.TYPE_TEXT_FLAG_MULTI_LINE != 0) { - // Send native Enter events so React Native decides between newline and - // submit/blur using its existing submitBehavior listener. - editor.dispatchKeyEvent( - android.view.KeyEvent( - android.view.KeyEvent.ACTION_DOWN, - android.view.KeyEvent.KEYCODE_ENTER, - ) - ) - editor.dispatchKeyEvent( - android.view.KeyEvent(android.view.KeyEvent.ACTION_UP, android.view.KeyEvent.KEYCODE_ENTER) - ) - } else { - editor.onEditorAction(EditorInfo.IME_ACTION_DONE) - } + dispatchKeyflowSubmit(editor) } private fun activate(action: String, text: String) { @@ -660,3 +655,20 @@ class KeyflowInputView(context: Context, private val expoContext: AppContext) : } } } + +/** + * Sends Return through Android's editor APIs so React Native remains responsible for + * `submitBehavior`, `onSubmitEditing`, newline insertion, and blur behavior. + */ +internal fun dispatchKeyflowSubmit(editor: EditText) { + if (editor.inputType and android.text.InputType.TYPE_TEXT_FLAG_MULTI_LINE != 0) { + editor.dispatchKeyEvent( + android.view.KeyEvent(android.view.KeyEvent.ACTION_DOWN, android.view.KeyEvent.KEYCODE_ENTER) + ) + editor.dispatchKeyEvent( + android.view.KeyEvent(android.view.KeyEvent.ACTION_UP, android.view.KeyEvent.KEYCODE_ENTER) + ) + } else { + editor.onEditorAction(EditorInfo.IME_ACTION_DONE) + } +} diff --git a/android/src/main/java/com/keyflow/KeyflowKeyView.kt b/android/src/main/java/com/keyflow/KeyflowKeyView.kt index 2f6730d..13fedfd 100644 --- a/android/src/main/java/com/keyflow/KeyflowKeyView.kt +++ b/android/src/main/java/com/keyflow/KeyflowKeyView.kt @@ -34,6 +34,8 @@ internal class KeyflowKeyView( var circular = false var themeSection: String? = null var iconSize = if (action in listOf("delete", "submit")) 26f else 24f + private var actionIcon: String? = null + private var actionUsesText = false var onSlide: ((Float, Float) -> Unit)? = null var onSlideStart: (() -> Unit)? = null var onSlideEnd: (() -> Unit)? = null @@ -61,8 +63,19 @@ internal class KeyflowKeyView( private var sliding = false private val icon get() = - action in - listOf("shift", "capsLock", "tab", "delete", "submit", "paste", "hide", "nextLanguage") + actionIcon != null || + (!actionUsesText && + action in + listOf("shift", "capsLock", "tab", "delete", "submit", "paste", "hide", "nextLanguage")) + + fun setActionContent(value: String, icon: String?) { + label = value + contentDescription = value + actionIcon = icon + actionUsesText = icon == null + text = if (icon == null) value else "" + invalidate() + } private var repeating = false private var preferredSize = 22f @@ -327,7 +340,7 @@ internal class KeyflowKeyView( if (icon) KeyflowIcons.draw( canvas, - if (action == "shift" && isActivated) "shiftLocked" else action, + if (action == "shift" && isActivated) "shiftLocked" else actionIcon ?: action, bounds.exactCenterX(), bounds.exactCenterY() - keyDepth * density / 2, (sourceTheme.json diff --git a/android/src/main/java/com/keyflow/KeyflowKeyboardView.kt b/android/src/main/java/com/keyflow/KeyflowKeyboardView.kt index 2d69915..d21c6fa 100644 --- a/android/src/main/java/com/keyflow/KeyflowKeyboardView.kt +++ b/android/src/main/java/com/keyflow/KeyflowKeyboardView.kt @@ -559,7 +559,15 @@ internal class KeyflowKeyboardView( private fun styleKeys() { background = GradientDrawable().apply { setColor(theme.background) } - keys.forEach { it.applyTheme(theme) } + val content = theme.json.optJSONObject("returnKeyContent") + keys.forEach { + if (it.action == "submit") { + val text = content?.optString("text")?.takeIf(String::isNotEmpty) + val icon = content?.optString("icon")?.takeIf(String::isNotEmpty) ?: "checkmark" + it.setActionContent(text ?: "Submit", if (text == null) icon else null) + } + it.applyTheme(theme) + } updateToolbar() } diff --git a/docs/api.md b/docs/api.md index cb2c283..2f502ed 100644 --- a/docs/api.md +++ b/docs/api.md @@ -75,10 +75,12 @@ 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 | | `keyboardType` | `default`, `number-pad`, `decimal-pad`, `phone-pad` | +| `returnKeyContent` | Custom text or a portable native icon for Keyflow's submit key | | `keyflowTheme` | Partial overrides or a resolved theme | | `keyboardLanguages` | English/French language and QWERTY/AZERTY template entries | | `hapticsEnabled` | Optional key feedback, off by default | @@ -90,6 +92,25 @@ export function Input() { The app owns its editor and text. Use ordinary React Native `TextInput` props such as `value`, `defaultValue`, `onChangeText`, `onSubmitEditing`, `placeholderTextColor`, `accessibilityLabel`, `editable`, and `submitBehavior` directly on the input. Keyflow adds no input height, padding, border, color, or font. `onSubmitEditing` receives the standard React Native event, not a string. +Customize Keyflow's return key independently from submission behavior: + +```tsx +const { keyflowInputProps } = useKeyflow({ + returnKeyContent: { icon: 'send' }, +}); + +; + +// A multiline editor can use the same key to insert a newline. +; +``` + +The portable icon names are `return`, `arrow-right`, `checkmark`, `send`, and `search`. Choose either `text` or `icon`. The option affects only the custom keyboard; the system keyboard continues to follow the platform's `returnKeyType` and `enterKeyHint` behavior. + The hook returns: | Value | Purpose | @@ -102,7 +123,7 @@ Text state, input appearance, and composer content remain app-controlled. There Single-line and `multiline` inputs are supported. Set editor height, scrolling, and `numberOfLines` on the input. During trackpad movement, a floating caret follows continuous horizontal and vertical drag coordinates across text and blank space inside the input. The native editor resolves the insertion position through text hit testing, including soft wrapping; release removes the floating caret and restores the native caret at that position. The drag target is anchored at gesture start and remains independent of the snapped caret across short lines. Hold space on iOS, or use the space-slide gesture on Android. Return uses the native React Native editing pipeline and respects `submitBehavior`. -Call `useKeyflow(options)` and spread `keyflowInputProps` onto your `TextInput`. The hook creates a stable ref and includes it with the `showSoftInputOnFocus`, `onFocus`, and `onSelectionChange` bindings. The ref allows native keyboard attachment; the callbacks keep focus and cursor context synchronized. For custom components, forward the ref and bindings to the underlying `TextInput`, not a surrounding `View`. +Call `useKeyflow(options)` and spread `keyflowInputProps` onto your `TextInput`. The hook creates a stable ref and includes it with the `showSoftInputOnFocus`, `onFocus`, `onSelectionChange`, and `onLayout` bindings. The ref allows native keyboard attachment; the callbacks keep focus and cursor context synchronized and support automatic focus when an input mounts later. For custom components, forward the ref and bindings to the underlying `TextInput`, not a surrounding `View`. If you override `onLayout`, call `keyflowInputProps.onLayout?.(event)` from your handler too. Compose your own focus/selection callbacks with the bindings: diff --git a/docs/media/README.md b/docs/media/README.md index 270cfc9..4518f74 100644 --- a/docs/media/README.md +++ b/docs/media/README.md @@ -1,14 +1,14 @@ # README media -All six GIFs and MP4s were recorded again on 2026-09-15 using the keyboard implementation merged in `5bc4916`. They show the current example, including multiline trackpad movement. The themed stills and four default-layout previews retain their earlier provenance below. These are simulator/emulator demonstrations, not a comparison against Apple/Gboard or a claim of physical-device frame pacing. +The transition and trackpad clips were recorded on 2026-09-15 using the keyboard implementation merged in `5bc4916`. Both accent clips were replaced on 2026-09-16 from the current long-press implementation. The themed stills and four default-layout previews retain their earlier provenance below. These are simulator/emulator demonstrations, not a comparison against Apple/Gboard or a claim of physical-device frame pacing. | Files | Device and action | | ---------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | | `ios-transitions.mp4` / `.gif` | Stim-owned iPhone 17, iOS 26.5. Story Studio: two dismissal/refocus cycles | -| `ios-accents.mp4` / `.gif` | Same iPhone. Story Studio: two holds on E, sliding across accent choices | +| `ios-accents.mp4` / `.gif` | Same iPhone. Story Studio: hold E, slide the rose focus across several accents, and release to commit the focused choice | | `ios-trackpad.mp4` / `.gif` | Same iPhone. Native interaction example: reset the multiline fixture, hold space and move diagonally up/left and down/right; labels fade and return | | `android-transitions.mp4` / `.gif` | Stim-owned Android phone emulator, API 36, 1080 × 2400. Native interaction example: submit dismissal and refocus twice | -| `android-accents.mp4` / `.gif` | Same Android phone. Hold E and continuously slide left/right across alternatives | +| `android-accents.mp4` / `.gif` | Same Android phone. Story Studio: hold E, traverse both popup rows with the rose focus, and release to commit `É` | | `android-trackpad.mp4` / `.gif` | Same Android phone. Reset the multiline fixture, then one continuous space gesture moves horizontally and vertically | | `studio.jpg` | iPad Story Studio keyboard after accent input, captured on 2026-09-13 from `c4183a6` | | `transparent.jpg` | Same earlier iPad capture. Transparency example at 35% panel and 70% keys | @@ -22,7 +22,7 @@ All six GIFs and MP4s were recorded again on 2026-09-15 using the keyboard imple - The multiline text is seeded through the example’s visible Reset Multiline action. The recordings demonstrate movement through that input, not typing of the fixture text. - No keys, colors, text, backgrounds or cursor motion were reconstructed. The capture harness is separate from the regression-suite count. Documentation media is outside the npm package’s `files` allowlist. -To reproduce, launch the current example with Stim. Open Story Studio on iPhone for accents/transitions, or Compare native interactions for multiline trackpad movement. On Android, use Compare native interactions for all three actions. Keep the host display awake for simulator/emulator UI recording. +To reproduce, launch the current example with Stim. Use Story Studio for accents and transitions on both platforms. Use Compare native interactions for multiline trackpad movement. Keep the host display awake for simulator/emulator UI recording. ## Default-layout previews diff --git a/docs/media/android-accents.gif b/docs/media/android-accents.gif index adf24ba..bf33382 100644 Binary files a/docs/media/android-accents.gif and b/docs/media/android-accents.gif differ diff --git a/docs/media/android-accents.mp4 b/docs/media/android-accents.mp4 index ab2a522..0dd74af 100644 Binary files a/docs/media/android-accents.mp4 and b/docs/media/android-accents.mp4 differ diff --git a/docs/media/ios-accents.gif b/docs/media/ios-accents.gif index e5caa57..2c8e54a 100644 Binary files a/docs/media/ios-accents.gif and b/docs/media/ios-accents.gif differ diff --git a/docs/media/ios-accents.mp4 b/docs/media/ios-accents.mp4 index d925446..853abee 100644 Binary files a/docs/media/ios-accents.mp4 and b/docs/media/ios-accents.mp4 differ diff --git a/example/src/App.tsx b/example/src/App.tsx index b0fa390..8e19b26 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -14,7 +14,11 @@ 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'; +import { ReturnActionScreen } from './screens/ReturnActionScreen'; export type Routes = { + Teardown: undefined; + ReturnActions: undefined; Showcase: undefined; Transparency: undefined; Interactions: undefined; @@ -82,6 +86,16 @@ export default function App() { component={InteractionScreen} options={{ title: 'Native interaction tests' }} /> + + @@ -188,7 +189,7 @@ export function InteractionScreen({ ); return ( - + value={mode} options={[ @@ -207,7 +208,7 @@ export function InteractionScreen({ if (!running) void switchMode(next); }} /> - + Use the same cases with each keyboard. Compare accents, cursor movement and held delete. @@ -223,6 +224,7 @@ export function InteractionScreen({ Text: {text || '(empty)'} diff --git a/example/src/screens/KeyboardScreen.tsx b/example/src/screens/KeyboardScreen.tsx index 03acb1e..690728f 100644 --- a/example/src/screens/KeyboardScreen.tsx +++ b/example/src/screens/KeyboardScreen.tsx @@ -65,6 +65,7 @@ export const KeyboardScreen = observer(function KeyboardScreenContent({ keyboardMode: mode, keyboardAppearance: dark ? 'dark' : 'light', keyflowTheme: game ? studioTheme : undefined, + returnKeyContent: game ? { icon: 'send' } : undefined, hapticsEnabled: haptics, onKeyboardModeChange: setMode, onKeyboardFrameChange: (next) => { diff --git a/example/src/screens/LongPressScreen.tsx b/example/src/screens/LongPressScreen.tsx index 3b49195..e060d6e 100644 --- a/example/src/screens/LongPressScreen.tsx +++ b/example/src/screens/LongPressScreen.tsx @@ -23,6 +23,7 @@ export function LongPressScreen() { const [diagnostic, setDiagnostic] = useState('Ready for comparison.'); const header = useHeaderHeight(); const { inputRef: input, keyflowInputProps: bindings } = useKeyflow({ + autoFocus: true, keyboardMode: mode, keyboardAppearance: 'light', }); @@ -126,7 +127,6 @@ export function LongPressScreen() { (null); + const [submitCount, setSubmitCount] = useState(0); + const [note, setNote] = useState('First line'); + const [unexpectedNoteSubmits, setUnexpectedNoteSubmits] = useState(0); + const { keyflowInputProps: sendInputProps } = useKeyflow({ + keyflowTheme: studioTheme, + returnKeyContent: { icon: 'send' }, + }); + const { keyflowInputProps: newlineInputProps } = useKeyflow({ + keyflowTheme: studioTheme, + returnKeyContent: { text: 'New line' }, + }); + const lineCount = note.split('\n').length; + + return ( + + + + + One key, two actions + + + The Keyflow option changes what Return displays. The TextInput’s + submitBehavior decides what pressing it does. + + + + + { + setSubmitted(event.nativeEvent.text); + setSubmitCount((count) => count + 1); + }} + style={{ + height: 88, + paddingVertical: 12, + textAlignVertical: 'top', + }} + /> + + {submitted === null + ? 'Nothing submitted yet.' + : `Submitted ${submitCount}×: ${submitted}`} + + + + + + setUnexpectedNoteSubmits((count) => count + 1) + } + style={{ + height: 116, + paddingVertical: 12, + textAlignVertical: 'top', + }} + /> + + {lineCount} {lineCount === 1 ? 'line' : 'lines'} · Submit events:{' '} + {unexpectedNoteSubmits} + + + + + ); +} + +function ExampleCard({ + title, + instruction, + children, +}: { + title: string; + instruction: string; + children: ReactNode; +}) { + return ( + + + + {title} + + + {instruction} + + + {children} + + ); +} diff --git a/example/src/screens/ShowcaseScreen.tsx b/example/src/screens/ShowcaseScreen.tsx index f519e9f..216d6c8 100644 --- a/example/src/screens/ShowcaseScreen.tsx +++ b/example/src/screens/ShowcaseScreen.tsx @@ -39,6 +39,26 @@ const sections = [ sample: '↑ · ↓', color: '#E9F6F1', }, + { + route: 'Teardown', + accessibilityLabel: 'Test focused teardown', + eyebrow: 'Focus · close · unmount', + title: 'Focused teardown', + description: + 'Close a focused preview and unmount its entire Keyflow hook.', + sample: '×', + color: '#EAF1FF', + }, + { + route: 'ReturnActions', + accessibilityLabel: 'Test return key actions', + eyebrow: 'Submit · New line', + title: 'Return key actions', + description: + 'Compare a custom send key with a multiline Return that inserts a new line.', + sample: '➤ ↵', + color: '#FFF2E8', + }, ], }, { diff --git a/example/src/screens/TeardownScreen.tsx b/example/src/screens/TeardownScreen.tsx new file mode 100644 index 0000000..84dda4c --- /dev/null +++ b/example/src/screens/TeardownScreen.tsx @@ -0,0 +1,89 @@ +import { useEffect, useRef, useState } from 'react'; +import { + Button, + Keyboard, + Platform, + Text, + TextInput, + View, +} from 'react-native'; +import { KeyflowAvoidingView, useKeyflow } from 'react-native-keyflow'; +import { studioTheme } from '../themes/studio'; + +function Preview({ onClose }: { onClose: () => void }) { + const [text, setText] = useState('Draft message'); + const { keyflowInputProps } = useKeyflow({ + autoFocus: true, + keyflowTheme: studioTheme, + }); + return ( + + + + Focused composer + + The whole composer must stay visible while Keyflow is open. + + +