Repository navigation
Add React Native device APIs to @effect/ui-native/kit - #542
Merged
Merged
Conversation
effect-bot
force-pushed
the
agent/nelson-effect-bot/eabedc3bb763
branch
3 times, most recently
from
November 27, 2026 12:25
3be4200 to
64588d5
Compare
Bundle sizeProduction build, gzip level 9 per chunk. Effect-only client: 26780 B gzip. Full report
|
effect-bot
force-pushed
the
agent/nelson-effect-bot/eabedc3bb763
branch
4 times, most recently
from
November 28, 2026 06:27
c8daca8 to
6024322
Compare
- Share one value cell between device sources and surface props - Compare surface props with Equal.equals - Guard a missing native module once, in device.promise - Let device.subscription report whether a message was sent, for BackHandler - Drop the withDevice and result aliases - Skip KeyboardAvoidingView renders for a layout that moved nothing
…er the inset changes
effect-bot
force-pushed
the
agent/nelson-effect-bot/eabedc3bb763
branch
from
November 28, 2026 06:53
6024322 to
41b6f19
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds React Native's device APIs to
@effect/ui-native/kit. They call the native modules andRCTDeviceEventEmitterdirectly, so none of them loads React Native's JavaScript wrappers.Closes EFF-4575
What's in it
The kit gets
KeyboardAvoidingViewas a component, and these namespaces:AccessibilityInfo,Alert,AppState,Appearance,BackHandler,Dimensions(withPixelRatio's helpers),I18nManager,Keyboard,Linking,PermissionsAndroid,PlatformColor(withDynamicColorIOSasPlatformColor.dynamic),Share,StatusBarandVibration.Each module exposes up to three forms:
Linking.openURL(url)andDimensions.get. When native can reject one, it fails withNative.DeviceError.update, such asKeyboard.DismissandAlert.Alert. A fallible one answers withResult<A, Native.DeviceError>.Dimensions.onChangeandKeyboard.changes. The Subscriptions are built onSubscription.direct, so they send the current value when they start and then each change.Every module reads its device from
Native.Device, aContext.ReferencethatNativeApp.registerprovides. The reference's default is an inert device, so code without a device (a test, say) gets safe values: a 0×0 window at scale 1, the"active"app state, a hidden keyboard, no permissions, and so on.Shared changes
@effect/ui:Subscription.direct'sattachcan return{ close, start }.startruns after the Subscription starts, outside render, which is how a source sends its current value first.Native:Native.Device,Native.DeviceError, andNative.Colorwidened with a brandedNativeColorforPlatformColor.Native.HostgainsaccessibilityEvent, whichAccessibilityInfo.focususes.NativeApp:setSurfacePropsis no longer a no-op.Surface.initialPropsis renamed topropsand follows native's updates,Surface.onPropslistens for them, andmountre-runs an Effectpropswhen they change. It listens before the first run, and an update that arrives during it replaces that run, and each run gets the same services as the first. This rename is breaking. The package is unreleased.NativeHosttracks the focused input, soKeyboard.dismisscan blur it.Choices worth a look
PlatformColor.make({ ios, android, fallback })builds one object with bothsemanticandresource_paths. Each platform's C++ parser reads its own key plusfallback, so one value works on both platforms.PlatformColor.dynamicaddsresource_paths: []and an Android fallback, eitherandroidorlight.androidis required by the type whenlightis itself a native colour. Without that, Android would get no colour at all.BackHandler.onPresskeeps a stack per device, and the latest handler gets each press first. A handler that returnsundefinedpasses the press on. When nothing takes it, Android's default runs. The README explains how this works alongside React Native's ownBackHandler.StatusBar.configureis a Subscription that works like RN's<StatusBar>stack: for each field, the latest one wins, and stopping restores the one before.setStyleandsetHiddenset the value that shows when noconfiguresets that field.Alertbuttons carry IDs, andAlert.alertreturns the ID of the button that was pressed (undefinedon a dismissal). The result type includes the default"ok"unless the options' type requiresbuttonswith at least one button.KeyboardAvoidingView's padding behavior adds the inset to the consumer's own bottom padding. The inset is computed from the view's bottom edge minus whatever movement of that edge the adjustment itself caused (at most the change in padding, height or position), so it settles after one layout however the parent places the view.PermissionsAndroid.Permissionis a union of string literals. Off Android,checkgivesfalseandrequestgives"denied", and neither calls native.Share.sharerequires amessageor aurlin its type, and fails withDeviceErrorwithout either (iOS never answers then). ItstintColoris a colour string or number, since iOS's sheet takes only a processed number.addListener/removeListenersare only called on iOS.Reviewing
There's one commit per module after the first. The first commit holds the shared runtime changes and is the one to read closely. The module commits follow the same shape and mostly stand alone.
kit/internal/device.ts, which arrives withDimensions, holds the shared helpers:source,observe,subscription,promiseandcallback.Verification
packages/ui-native/test/kit, written against a fake device (test/utils/FakeDevice.ts).pnpm check, the tests tsconfig, dprint, oxlint and vitest foruiandui-nativeall pass (1571 tests).NativeApp.registerand the kit in a bare JS context. The context has fake TurboModules and React Native's realRCTDeviceEventEmitter,TurboModuleRegistry,PlatformandprocessColor. On both Android and iOS I checked:Dimensions,Appearance,AppStateandKeyboard.BackHandler: the default action runs once with no handler, never while a handler takes the press, and once again after the handler closes.IntentAndroidon Android andLinkingManageron iOS.StatusBarpasses the animation arguments to iOS only.PermissionsAndroiddoesn't call native off Android.AccessibilityInfouses the right module per platform.PlatformColorvalues pass throughprocessColorunchanged, and iOS resolvesdynamicto numbers.react-nativefile, React, the renderer orInitializeCore. Each module is 0.6 to 1.6 KB minified, plus 2.7 KB of internals they all share. These figures are before Vite's tree-shaking.