@rootnative/web 0.0.0-alpha.1 → 0.0.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/llms.txt CHANGED
@@ -6,8 +6,8 @@
6
6
  > rendering, and SEO tags. It doesn't use react-native-web.
7
7
 
8
8
  Status: early alpha. The API can change between releases. Every component and
9
- API has tests that run in a real Chromium browser. Firefox and Safari aren't in
10
- the test run yet.
9
+ API has tests that run in real browsers: Chromium, Firefox, and WebKit, the
10
+ engine of Safari.
11
11
 
12
12
  Docs: https://rootnative.github.io/web/
13
13
  Full: https://rootnative.github.io/web/llms-full.txt
@@ -22,9 +22,17 @@ Peers: react ^19.0.0, react-dom ^19.0.0. ESM only.
22
22
  1. Add the Vite plugin (Vite 8) to vite.config.ts:
23
23
  import { rootnative } from '@rootnative/web/vite'
24
24
  plugins: [react(), rootnative()]
25
+ With Reanimated, or a library built on it: rootnative({ worklets: true }).
26
+ It runs the Babel plugin of react-native-worklets on the app code and the
27
+ libraries. The app needs react-native-worklets and @babel/core.
25
28
  It resolves react-native to @rootnative/web (the exact name only), resolves
26
29
  .web.* files first, defines __DEV__ (true on the dev server, false in a
27
30
  production build, from NODE_ENV), and puts 'web' in place of Platform.OS.
31
+ It also defines global as globalThis, resolves
32
+ @react-native/assets-registry/registry to @rootnative/web/assets-registry,
33
+ resolves the two react-native-web style files that Reanimated 4 imports to
34
+ @rootnative/web/style, and gives pre-bundled dependencies the .web.*
35
+ extensions.
28
36
  An alias or a __DEV__ define in your own config wins.
29
37
  2. Add src/react-native.d.ts (in a folder that tsconfig.json includes):
30
38
  declare module 'react-native' { export * from '@rootnative/web' }
@@ -43,9 +51,11 @@ Browsers: Chrome 95, Edge 95, Firefox 93, Safari 15.1, iOS Safari 15.1.
43
51
 
44
52
  Without the plugin (another bundler): alias the exact name react-native to
45
53
  @rootnative/web, put a .web variant of each extension first, and define
46
- __DEV__. In Vite, define it in define and in
47
- optimizeDeps.rolldownOptions.transform.define: the dependency optimizer
48
- doesn't apply define. Platform.OS then stays a read at run time.
54
+ __DEV__ and global (as globalThis). In Vite, set the defines in define and in
55
+ optimizeDeps.rolldownOptions.transform.define, and the extensions in
56
+ resolve.extensions and optimizeDeps.rolldownOptions.resolve.extensions: the
57
+ dependency optimizer has its own. Add the compat aliases that a library
58
+ needs. Platform.OS then stays a read at run time.
49
59
 
50
60
  Server rendering with Vite: the plugin applies to app code on the server. A
51
61
  dependency that Vite leaves to Node gets no __DEV__ and throws a
@@ -60,30 +70,45 @@ ReferenceError. Add it to ssr.noExternal.
60
70
  renderStyleTags, styleTagsHTML, StyleRegistry.
61
71
  - @rootnative/web/vite: rootnative(), the Vite plugin. Only in vite.config.ts.
62
72
 
73
+ Libraries: react-native-svg, react-native-safe-area-context, and
74
+ @react-native-async-storage/async-storage need nothing more. Reanimated and
75
+ libraries on it need rootnative({ worklets: true }). An icon set of
76
+ @react-native-vector-icons needs its font from the app: import the .ttf of
77
+ the package with ?url, then document.fonts.add(new FontFace(name, url)).
78
+ Set skipLibCheck: true, because the type files of a native library import
79
+ the real react-native types.
80
+
63
81
  Import /dom and /server only in code that runs on the web.
64
82
 
65
83
  ## What ships
66
84
 
67
- Components: View, Text, Image, Pressable, ScrollView, FlatList, TextInput,
68
- StatusBar.
85
+ Components: View, Text, Image, Pressable, TouchableHighlight,
86
+ TouchableNativeFeedback, TouchableOpacity, TouchableWithoutFeedback, Button,
87
+ ScrollView, FlatList, RefreshControl, TextInput, Switch, ActivityIndicator,
88
+ Modal, KeyboardAvoidingView, StatusBar.
69
89
 
70
90
  APIs: StyleSheet, Platform, Dimensions, useWindowDimensions, Appearance,
71
- useColorScheme, AccessibilityInfo, I18nManager, BackHandler, PixelRatio,
72
- processColor, PanResponder, usePressability.
91
+ useColorScheme, AppState, Keyboard, Linking, Alert, Share, Vibration, Clipboard,
92
+ AccessibilityInfo, I18nManager, BackHandler, PixelRatio, processColor,
93
+ PanResponder, usePressability.
94
+
95
+ Compat, for libraries only, do not call in app code: unstable_createElement,
96
+ findNodeHandle, TurboModuleRegistry.
73
97
 
74
98
  NOT IMPLEMENTED, do not import:
75
- - Button, ActivityIndicator, Switch, RefreshControl, Modal, TouchableOpacity,
76
- TouchableHighlight, TouchableWithoutFeedback, TouchableNativeFeedback.
77
- - Alert, AppState, Linking, Share, Vibration, Clipboard.
78
99
  - SectionList, VirtualizedList, Animated, LayoutAnimation.
79
- - onPressIn, onPressOut, onLongPress on Text. onPress on Text works.
80
100
  - A Next.js plugin, and templates for a Vite app with and without server
81
101
  rendering.
82
102
 
83
103
  Out of scope: Expo, Metro, React 18, CommonJS, Flow.
84
104
 
85
- A component ref is the DOM element. View has no measure, measureInWindow,
86
- measureLayout, or setNativeProps: use onLayout or getBoundingClientRect().
105
+ A component ref is the DOM element, typed HostInstance (ViewInstance,
106
+ TextInstance, ImageInstance, PressableInstance). It has measure(callback),
107
+ measureInWindow(callback), measureLayout(ancestor, onSuccess, onFail), and
108
+ setNativeProps({ style }). Each one calls its callback at once, with CSS
109
+ pixels from getBoundingClientRect(). The window is the visible area.
110
+ setNativeProps writes an inline style, and any other prop has no effect.
111
+ Type a ref as useRef<ViewInstance>(null), not useRef<HTMLElement>(null).
87
112
  ScrollView, FlatList, and TextInput add the methods listed below.
88
113
 
89
114
  ## Semantic HTML
@@ -128,18 +153,27 @@ only). Any other prop that isn't a React Native prop is dropped.
128
153
  aspectRatio, and fontWeight stay unitless. Strings pass through.
129
154
  - Colors use the React Native parser. A color it can't parse is dropped.
130
155
  - flex: 1 is 1 1 0%. flex: 0 is 0 0 auto. flex: -1 is 0 1 auto.
131
- - A longhand wins over a shorthand, whatever the key order.
156
+ - Any style wins over a default (flex: 1 beats the default flexShrink 0). A
157
+ longhand wins over a shorthand, whatever the key order.
132
158
  - Start and end props (marginStart, paddingEnd, start, end, borderStartWidth,
133
159
  borderTopStartRadius, ...) become logical CSS and flip in right-to-left.
134
- - marginLeft, paddingLeft, left, and their right partners stay physical in a
135
- right-to-left layout. Native swaps them by default. Use start and end props
136
- for anything that must follow the direction.
160
+ - marginLeft, paddingLeft, left, the left and right borders and corners, and
161
+ their right partners swap sides in a right-to-left layout, as on native.
162
+ They compile to logical CSS. I18nManager.swapLeftAndRightInRTL(false)
163
+ before the first render keeps them physical. A start or end style wins
164
+ over a left or right style of the same side.
137
165
  - transform, boxShadow, and filter take the React Native array or a CSS
138
166
  string. shadow* props become box-shadow when boxShadow isn't set.
139
167
  textShadow* props become text-shadow.
140
168
  - fontFamily 'System' is the browser's system font stack. Named font weights
141
169
  become numbers.
142
170
  - elevation, borderCurve, includeFontPadding, overlayColor: no web effect.
171
+ - Types: the style props take React Native 0.88's ViewStyle, TextStyle, and
172
+ ImageStyle, and StyleSheet.create checks each key and value. touchAction is
173
+ the one web-only key. transform takes no Animated value, and resizeMode has
174
+ no 'none' yet. Any other CSS property passes through at runtime but needs a
175
+ cast: { transition: '...' } as ViewStyle, or as unknown as ViewStyle for a
176
+ value that React Native's type doesn't allow.
143
177
 
144
178
  ## Components
145
179
 
@@ -152,10 +186,16 @@ Text
152
186
  - numberOfLines 1 ends the line with an ellipsis. A larger number clamps.
153
187
  - ellipsizeMode: tail and clip. head and middle show the ellipsis at the end.
154
188
  - selectable is true by default on the web (false on native).
155
- - onPress gets the DOM click event. onClick runs first, and preventDefault()
156
- in it stops onPress. disabled sets aria-disabled and stops onPress.
157
- - A Text with onPress is a span that a keyboard can't focus. Use href to go to
158
- a page, or wrap it in a Pressable with role="button" for an action.
189
+ - onPress, onPressIn, onPressOut, onLongPress, and pressRetentionOffset work
190
+ as on Pressable. The event is a GestureResponderEvent. As on native, only
191
+ onPress or onLongPress makes a Text pressable. suppressHighlighting is
192
+ ignored, as on Android.
193
+ - A pressable Text with no role has role="link", is in the tab order, and
194
+ Enter or Space presses it. With href it renders an <a>. role="button"
195
+ renders a <button>. disabled sets aria-disabled, and the Text isn't
196
+ pressable, so a pressable parent gets the press.
197
+ - On a pressable Text, onClick and the other DOM handlers run before the press
198
+ handlers, and both run.
159
199
 
160
200
  Image
161
201
  - Renders a div box with an <img> inside. The style sizes the box. With no
@@ -182,6 +222,9 @@ Pressable
182
222
  130 ms, as on native.
183
223
  - onPress gets the pointer up event, or the click event for a keyboard or
184
224
  assistive technology press. preventDefault() on it cancels the click.
225
+ - The click that follows a tap stops when it lands outside the pressed
226
+ element, for example on a modal that the press opened. A click on the
227
+ pressed element goes through.
185
228
  - hitSlop grows the hit area with a ::before box. A parent with overflow
186
229
  hidden clips it.
187
230
  - pressRetentionOffset defaults to 20 on three sides and 30 at the bottom.
@@ -189,6 +232,62 @@ Pressable
189
232
  - disabled sets aria-disabled, leaves the tab order, and stops every press.
190
233
  - android_ripple, android_disableSound, blockNativeResponder: ignored.
191
234
 
235
+ TouchableHighlight
236
+ - The press handling of Pressable, with no minimum press duration. A div
237
+ around one child that takes a style. role="button" renders a button.
238
+ - While pressed: underlayColor (default black) as the background, and
239
+ activeOpacity (default 0.85) on the child. After onPress, the underlay
240
+ stays for delayPressOut ms, so a short tap shows it. No press handler, no
241
+ underlay. testOnly_pressed shows it. onShowUnderlay, onHideUnderlay.
242
+ - Give the child an opaque background color, or the underlay shows at full
243
+ strength.
244
+ - In the tab order only with onPress. onFocus and onBlur fire.
245
+ rejectResponderTermination sets touch-action: none.
246
+
247
+ TouchableNativeFeedback
248
+ - Works as TouchableWithoutFeedback, with no ripple, as on iOS. background
249
+ and useForeground are ignored.
250
+ - SelectableBackground(), SelectableBackgroundBorderless(), and Ripple(color,
251
+ borderless, rippleRadius) return the objects of React Native.
252
+ canUseNativeForeground() is false. Call Ripple outside a component: the
253
+ React Compiler lint reads a capitalized call as a component.
254
+
255
+ TouchableOpacity
256
+ - The press handling of Pressable, with no minimum press duration.
257
+ role="button" renders <button type="button">. Without a role, a div.
258
+ - Dims to activeOpacity (default 0.2) at once when a press starts, and over
259
+ 150 ms when the pointer comes back into the press area. Fades back to the
260
+ style's opacity over 250 ms when the press ends or the pointer leaves, and
261
+ when disabled or the style's opacity changes. Easing.inOut(Easing.quad),
262
+ through the Web Animations API, with no new render.
263
+ - In the tab order only with onPress, as on native. onFocus and onBlur fire
264
+ (native doesn't call them). rejectResponderTermination sets touch-action:
265
+ none. hitSlop and pressRetentionOffset as on Pressable.
266
+ - touchSoundDisabled, hasTVPreferredFocus, nextFocus*: ignored.
267
+
268
+ TouchableWithoutFeedback
269
+ - No element of its own. Its only child gets the press handlers (the child's
270
+ own DOM handlers run first), the accessibility props, role, testID,
271
+ nativeID, id, and onLayout. style stays out, as on native.
272
+ - onFocus and onBlur replace the child's. Without them, the child keeps its
273
+ own. The child is in the tab order only with onPress and not disabled.
274
+ - hitSlop goes to the child, but a View doesn't grow its hit area yet.
275
+ rejectResponderTermination is ignored.
276
+
277
+ Button
278
+ - <button type="button"> with the title in a Text, on TouchableOpacity: it
279
+ dims to 0.2 while pressed. title must be a string, or Button throws.
280
+ - The look of the Android button: background #2196F3, white text, weight 500,
281
+ radius 2, 8 px around the title. color sets the background. The title keeps
282
+ its case (Android makes it uppercase). No elevation.
283
+ - disabled (or aria-disabled, or accessibilityState.disabled): background
284
+ #dfdfdf, text #a1a1a1, aria-disabled, out of the tab order, no press.
285
+ - Takes only the props of React Native's Button: no style, no children. For
286
+ another look, use Pressable with role="button".
287
+ - accessibilityLanguage sets lang. accessibilityActions,
288
+ onAccessibilityAction, touchSoundDisabled, hasTVPreferredFocus, nextFocus*:
289
+ ignored. Ref: the button element.
290
+
192
291
  ScrollView
193
292
  - Scrolls its own box, not the document. On a phone, the browser's address
194
293
  bar doesn't hide as it scrolls.
@@ -200,8 +299,9 @@ ScrollView
200
299
  - scrollEnabled={false} hides the overflow.
201
300
  - snapToInterval, snapToOffsets, pagingEnabled snap after the scroll settles.
202
301
  - stickyHeaderIndices: vertical only. keyboardDismissMode: on-drag works.
203
- - refreshControl wraps the scroller. RefreshControl isn't in the package, so
204
- pass your own component.
302
+ - refreshControl wraps the scroller and gets the style props that place the
303
+ box (margins, flex, sizes, position, transform, gaps), as on Android. The
304
+ scroller fills it and keeps the rest of the style.
205
305
  - Ref: the scroll element plus scrollTo({ x, y, animated }) (animated defaults
206
306
  to true), scrollToEnd({ animated }), getScrollableNode(),
207
307
  getInnerViewNode(). flashScrollIndicators() does nothing.
@@ -210,6 +310,22 @@ ScrollView
210
310
  - Native-only props (bounces, decelerationRate, contentInset, the zoom props,
211
311
  ...) are ignored.
212
312
 
313
+ RefreshControl
314
+ - Pass it to ScrollView as refreshControl, or give FlatList onRefresh and
315
+ refreshing. Pull to refresh with TOUCH ONLY: mouse, pen, and keyboard have
316
+ no pull, so add a refresh button too.
317
+ - A pull starts at the top of the list when the finger first moves down. The
318
+ indicator moves half the finger distance. A release after 128 px of finger
319
+ calls onRefresh. onRefresh must set refreshing to true at once, or the
320
+ indicator goes back. No pull while refreshing or with enabled={false}.
321
+ - In a flipped scroller (an inverted FlatList), the indicator sits at the
322
+ bottom and the pull goes up, as on native.
323
+ - Android's look: an arc on a white disc (40 px, size="large" 56 px), at rest
324
+ 64 px under progressViewOffset minus the disc. colors[0], else tintColor,
325
+ else black, is the arc. progressBackgroundColor is the disc.
326
+ - title is the accessible name; no visible text. titleColor: no effect.
327
+ - View props and the ref go to the wrapper, which has aria-busy.
328
+
213
329
  FlatList
214
330
  - NO VIRTUALIZER. It renders every item. Load a long list in pages with
215
331
  onEndReached.
@@ -224,7 +340,10 @@ FlatList
224
340
  stickyHeaderIndices, and the ScrollView props.
225
341
  - onEndReached fires once per content length. The default threshold is 2 px.
226
342
  A list shorter than its viewport fires it after mount.
227
- - onRefresh and refreshing show no indicator. Pass refreshControl instead.
343
+ - onRefresh and refreshing wrap the scroller in a RefreshControl, with
344
+ progressViewOffset, as on native. With onRefresh, refreshing must be a
345
+ boolean, or the list throws. A refreshControl prop wins.
346
+ renderScrollComponent gets the three props and adds its own control.
228
347
  - Ref: scrollToOffset, scrollToIndex (a row index with numColumns),
229
348
  scrollToItem, scrollToEnd, recordInteraction, getScrollableNode.
230
349
  onScrollToIndexFailed never fires.
@@ -244,9 +363,65 @@ TextInput
244
363
  values map (name-given to given-name, sms-otp to one-time-code).
245
364
  - A value with no change handler stays fixed, with no React warning.
246
365
  - Ref: the element plus clear(), isFocused(), getNativeRef(),
247
- setNativeProps({ text }). TextInput.State has currentlyFocusedInput(),
366
+ setNativeProps({ text, style }). TextInput.State has currentlyFocusedInput(),
248
367
  focusTextInput(element), blurTextInput(element).
249
368
 
369
+ Switch
370
+ - <input type="checkbox" role="switch">, transparent, over a drawn track and
371
+ thumb. The browser gives the press, Space, the focus, and <label for>.
372
+ - Controlled, as on native: it shows value (only true is on). A press calls
373
+ onChange (nativeEvent.value, nativeEvent.target), then onValueChange(value).
374
+ When value doesn't change, the switch goes back.
375
+ - The look of the Android switch: 40 by 20 px, track #939393 off and #A3D3CF
376
+ on, thumb #FAFAFA off and #009688 on. trackColor={{ false, true }} and
377
+ thumbColor replace them. The thumb moves over 150 ms, not with
378
+ prefers-reduced-motion. Right-to-left puts the on position at the left.
379
+ - disabled (or accessibilityState.disabled): the input is disabled, and the
380
+ switch has an opacity of 0.5.
381
+ - style, onLayout, and pointerEvents go to the root element, which has
382
+ alignSelf: flex-start. A width and height in style change the size. The
383
+ ref, id, testID, and the accessibility props go to the input.
384
+ - ios_backgroundColor, onTintColor, tintColor, thumbTintColor: ignored.
385
+
386
+ ActivityIndicator
387
+ - A spinner: an SVG that turns once each 0.75 s, in an element with
388
+ role="progressbar". size: small (20 px, the default), large (36 px), or a
389
+ number. color: the default is #999999.
390
+ - animating={false} stops and hides it, and it keeps its space.
391
+ hidesWhenStopped={false} keeps a stopped indicator visible.
392
+ - Two elements, as on native: style and onLayout go to a container that
393
+ centers the indicator. The ref and the other props go to the indicator.
394
+ - It turns also with prefers-reduced-motion.
395
+
396
+ Modal
397
+ - A <dialog> opened with showModal(), in a portal on <body>: the top layer,
398
+ above every zIndex. The rest of the page is inert and doesn't scroll.
399
+ - visible decides (default true). Escape, and the back gesture of Chrome on
400
+ Android, call onRequestClose: hide the modal there. While visible is true,
401
+ the modal stays open.
402
+ - onShow fires once per show, when the enter animation ends. onDismiss fires
403
+ after visible becomes false and the exit animation ends, not on unmount.
404
+ - The focus moves into the modal (the first control, or the dialog itself),
405
+ and back to the opener when it hides.
406
+ - The modal stays in place when the keyboard opens: it undoes the move of the
407
+ page that Safari on iOS makes for a focused field. Use a
408
+ KeyboardAvoidingView inside it.
409
+ - A press inside doesn't reach a Pressable around the Modal. A nested modal
410
+ goes on top, and Escape closes the top one first.
411
+ - The children go in a box that fills the viewport: white, backdropColor, or
412
+ clear with transparent. style goes to the box. ref and modalRef are the
413
+ <dialog>. testID, aria props, and DOM handlers go to the <dialog>.
414
+ - Renders nothing on the server. It shows after hydration.
415
+ - animationType: slide (up from the bottom) or fade, 200 ms with the curves
416
+ of the Android modal; none (default) is instant. The modal stays until its
417
+ exit animation ends and takes no presses then; a nested modal closes at
418
+ once. Reduced motion: instant.
419
+ - presentationStyle, supportedOrientations, onOrientationChange,
420
+ allowSwipeDismissal, hardwareAccelerated, statusBarTranslucent,
421
+ navigationBarTranslucent: ignored.
422
+ - Firefox before 98 and Safari before 15.4 have no showModal(): a fixed box
423
+ on top, Escape works, the page isn't inert.
424
+
250
425
  StatusBar
251
426
  - backgroundColor writes <meta name="theme-color"> in the browser, after
252
427
  mount, so the server HTML doesn't have it. The last mounted StatusBar wins.
@@ -272,6 +447,62 @@ StatusBar
272
447
  prefers-color-scheme. setColorScheme('light' | 'dark') overrides it for the
273
448
  app and sets color-scheme on <html>. null or 'unspecified' clears it.
274
449
  addChangeListener(fn) returns { remove() }.
450
+ - AppState: currentState is 'active' while the page is visible, else
451
+ 'background' ('active' on the server). No 'inactive'. addEventListener:
452
+ 'change' (visibilitychange, and 'background' on pagehide), 'blur' and
453
+ 'focus' (the browser window, as on Android), 'memoryWarning' (never fires).
454
+ Returns { remove() }. An unknown event throws.
455
+ - Linking: openURL opens a URL of this site in this tab, a URL of another
456
+ site in a new tab (no opener; rejects when the browser blocks it, so call
457
+ it from a press handler), and mailto:, tel:, sms:, and other schemes from
458
+ this tab. javascript: and data: reject. A URL that isn't a string or is
459
+ empty throws at once. canOpenURL is true for each URL that openURL tries.
460
+ getInitialURL is the URL that the page loaded with (null on the server).
461
+ The 'url' event NEVER fires on the web: the router owns the URL. emit,
462
+ addListener, removeAllListeners, listenerCount work. openSettings rejects.
463
+ sendIntent rejects with 'Unsupported'. For a link that the user clicks,
464
+ prefer href on Text or View.
465
+ - Alert.alert(title, message?, buttons?, options?): a <dialog
466
+ role="alertdialog"> with showModal(), outside the React tree, with the look
467
+ of Android's alert (teal text buttons; dark gray card in the dark scheme,
468
+ from Appearance or userInterfaceStyle). All buttons show, in order; with
469
+ three, the first sits at the start. No buttons or [] give OK. A press closes
470
+ the alert, then calls onPress(). style 'destructive' is red text. Focus:
471
+ isPreferred, else the cancel button, else the first.
472
+ - Alert: Escape (and Chrome's Android back gesture) presses the style
473
+ 'cancel' button. Without one, Escape and a click outside close the alert
474
+ only with cancelable: true, then onDismiss runs. A new alert goes on top.
475
+ Alert.prompt does nothing yet (dev warning). On the server, nothing.
476
+ - Keyboard: as on Android. keyboardDidShow fires when the on-screen keyboard
477
+ shows and when its height changes, keyboardDidHide when it hides. The Will
478
+ and ChangeFrame events never fire. The keyboard comes from the visual
479
+ viewport, which shrinks by it, and counts only while a text field has the
480
+ focus; with navigator.virtualKeyboard.overlaysContent, from its rectangle.
481
+ Events: duration 0, easing 'keyboard', endCoordinates in CSS px (screenY =
482
+ top of the keyboard from the window top). dismiss() blurs the focused text
483
+ field. isVisible(), metrics(). scheduleLayoutAnimation does nothing. No
484
+ event on a desktop or with a hardware keyboard.
485
+ - KeyboardAvoidingView: React Native 0.88 math. behavior 'padding'
486
+ (paddingBottom), 'height' (first height less the covered part, flex: 0),
487
+ 'position' (inner view with contentContainerStyle, moved by bottom), none
488
+ (plain View). The frame comes from onLayout, so y is relative to the
489
+ parent: pass the distance to the window top in keyboardVerticalOffset, as on
490
+ native. No animation.
491
+ - Share: share({ title, message, url }) calls navigator.share with title,
492
+ text (the message), and url. Resolves { action: 'sharedAction' |
493
+ 'dismissedAction', activityType: null }; a closed sheet is dismissedAction.
494
+ REJECTS with 'Unsupported platform' where the browser has no share sheet
495
+ (for example Firefox on a desktop, or a page on plain http). Call it from a press handler. options
496
+ have no effect.
497
+ - Vibration: navigator.vibrate with Android's rules. A number is
498
+ milliseconds (default 400). An array is [wait, vibrate, wait, ...]. repeat
499
+ plays an array again until cancel(). Does nothing where the browser has no
500
+ Vibration API (Safari, iOS, most desktops).
501
+ - Clipboard (deprecated in React Native): setString writes with
502
+ navigator.clipboard.writeText, or a hidden textarea and
503
+ execCommand('copy') on a page with no Clipboard API. A refused write only
504
+ warns in development. getString reads with readText and REJECTS when the
505
+ browser refuses. Call both from a press handler.
275
506
  - AccessibilityInfo: reduce motion, reduce transparency, invert colors, and
276
507
  high contrast read live media queries, with change events.
277
508
  isScreenReaderEnabled, isAccessibilityServiceEnabled, isBoldTextEnabled, and
@@ -282,7 +513,7 @@ StatusBar
282
513
  tabIndex={-1} so that it can take focus.
283
514
  - I18nManager: isRTL reads the dir of <html> each time. forceRTL sets dir on
284
515
  <html> at once. allowRTL(false) changes only what isRTL reports.
285
- swapLeftAndRightInRTL stores the flag and has no effect on styles. isRTL is
516
+ swapLeftAndRightInRTL(false) keeps left and right styles physical. isRTL is
286
517
  false on the server.
287
518
  - BackHandler: listeners register and never fire. exitApp() does nothing. Use
288
519
  the history API of your router.
@@ -292,8 +523,10 @@ StatusBar
292
523
  - processColor: an unsigned 32-bit ARGB integer, as on iOS. null for a color
293
524
  it can't parse.
294
525
  - PanResponder: runs on pointer events. panHandlers are six pointer handlers;
295
- spread them on a View. Set touchAction: 'none' in the style (or 'pan-y' for
296
- a horizontal drag in a vertical scroll), or the browser scrolls instead.
526
+ spread them on a View. While a responder holds the gesture, the page
527
+ doesn't scroll (onShouldBlockNativeResponder false lets it scroll). A
528
+ responder that takes the gesture on a move needs touchAction: 'none' in
529
+ the style (or 'pan-y' for a horizontal drag in a vertical scroll).
297
530
  The element captures the pointer at the grant. Negotiation works as on
298
531
  native. dx and dy are CSS pixels; vx and vy are pixels per millisecond.
299
532
  onShouldBlockNativeResponder is ignored. getInteractionHandle() is null.
@@ -301,6 +534,22 @@ StatusBar
301
534
  the native responder handlers. Spread them on a View. Memoize the config.
302
535
  A null config returns null. hitSlop doesn't grow the hit area. Set
303
536
  touchAction yourself for cancelable={false}.
537
+ - unstable_createElement(type, props): compat, not in React Native. Renders an
538
+ element from React Native props: style compiles to class names, the
539
+ accessibility props become ARIA attributes, onPress and the responder
540
+ handlers are dropped, every other prop goes to the element. No style reset.
541
+ - findNodeHandle(value): compat. Returns the DOM element of a ref, of an
542
+ element, or of a ScrollView ref. A number comes back as it is. null for a
543
+ class component instance.
544
+ - TurboModuleRegistry: compat. get() returns null, getEnforcing() throws.
545
+ - @rootnative/web/assets-registry: compat entry with registerAsset and
546
+ getAssetByID. The Vite plugin aliases @react-native/assets-registry/registry
547
+ to it. Empty unless your code registers an asset.
548
+ - @rootnative/web/style: compat entry for Reanimated 4. createReactDOMStyle
549
+ (also the default export) gives inline DOM style values, shorthands first.
550
+ createTransformValue and createTextShadowValue give CSS values. Without the
551
+ Worklets Babel plugin, pass the shared values as a dependency array to each
552
+ Reanimated hook.
304
553
 
305
554
  ## Server rendering
306
555
 
@@ -324,7 +573,7 @@ Render the whole <html> document with React, not only the app:
324
573
  - Write the style tags after the render ends.
325
574
  - Render <head> with React, so the tags of Head land in it. Pasted into a
326
575
  template, they land at the start of <body>.
327
- - renderStyleTags(registry) returns the same two <style> elements as React
576
+ - renderStyleTags(registry) returns the same three <style> elements as React
328
577
  elements.
329
578
  - The client calls hydrateRoot(root, <App />) with no provider. It adopts the
330
579
  server's <style> elements, so it inserts no rule twice.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rootnative/web",
3
- "version": "0.0.0-alpha.1",
3
+ "version": "0.0.0-alpha.3",
4
4
  "description": "A standalone web runtime for React Native apps",
5
5
  "license": "MIT",
6
6
  "homepage": "https://rootnative.github.io/web/",
@@ -32,8 +32,10 @@
32
32
  ],
33
33
  "exports": {
34
34
  ".": "./dist/index.js",
35
+ "./assets-registry": "./dist/assets-registry/index.js",
35
36
  "./dom": "./dist/dom/index.js",
36
37
  "./server": "./dist/server/index.js",
38
+ "./style": "./dist/style/index.js",
37
39
  "./vite": "./dist/vite/index.js",
38
40
  "./package.json": "./package.json"
39
41
  },
@@ -50,14 +52,23 @@
50
52
  "peerDependencies": {
51
53
  "react": "^19.0.0",
52
54
  "react-dom": "^19.0.0",
55
+ "@babel/core": "^7.0.0",
56
+ "react-native-worklets": ">=0.5.0",
53
57
  "vite": "^8.0.0"
54
58
  },
55
59
  "peerDependenciesMeta": {
60
+ "@babel/core": {
61
+ "optional": true
62
+ },
63
+ "react-native-worklets": {
64
+ "optional": true
65
+ },
56
66
  "vite": {
57
67
  "optional": true
58
68
  }
59
69
  },
60
70
  "devDependencies": {
71
+ "@babel/core": "7.29.13",
61
72
  "@types/react": "19.3.0",
62
73
  "@types/react-dom": "19.3.0",
63
74
  "@vitejs/plugin-react": "6.1.2",
@@ -66,6 +77,8 @@
66
77
  "playwright": "1.64.1",
67
78
  "react": "19.3.1",
68
79
  "react-dom": "19.3.1",
80
+ "react-native": "0.88.1",
81
+ "react-native-worklets": "0.13.0",
69
82
  "tsdown": "0.23.4",
70
83
  "vite": "8.3.5",
71
84
  "vitest": "5.0.5"
@@ -1 +0,0 @@
1
- {"version":3,"file":"StyleRegistryContext-D6yDrZk0.js","names":[],"sources":["../src/style/registry.ts","../src/style/StyleRegistryContext.ts"],"sourcesContent":["import { hasDOM } from '../utils/env'\nimport type { CSSDeclarations } from './types'\n\n// Two style elements: shorthand rules first, longhand rules after them. With equal\n// specificity the later sheet wins, so a longhand always beats a shorthand, as on native.\nexport const SHORTHAND_STYLE_ID = 'rootnative-style-shorthand'\nexport const LONGHAND_STYLE_ID = 'rootnative-style-longhand'\n\nconst shorthandProperties: ReadonlySet<string> = new Set([\n 'border',\n 'borderBlock',\n 'borderColor',\n 'borderInline',\n 'borderRadius',\n 'borderStyle',\n 'borderWidth',\n 'flex',\n 'flexFlow',\n 'gap',\n 'inset',\n 'insetBlock',\n 'insetInline',\n 'margin',\n 'marginBlock',\n 'marginInline',\n 'outline',\n 'overflow',\n 'padding',\n 'paddingBlock',\n 'paddingInline',\n 'textDecoration',\n])\n\nconst toKebab = (name: string): string => name.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`)\n\nconst hash = (input: string): string => {\n let h = 0x811c9dc5\n for (let i = 0; i < input.length; i++) {\n h ^= input.charCodeAt(i)\n h = Math.imul(h, 0x01000193)\n }\n return (h >>> 0).toString(36)\n}\n\nexport type StyleSheets = { shorthand: CSSStyleSheet | null; longhand: CSSStyleSheet | null }\n\nexport class StyleRegistry {\n private readonly classNames = new Map<string, string>()\n private readonly adopted = new Set<string>()\n private readonly shorthandRules: string[] = []\n private readonly longhandRules: string[] = []\n private readonly sheets: StyleSheets\n\n constructor(sheets: StyleSheets = { shorthand: null, longhand: null }) {\n this.sheets = sheets\n this.adopt(sheets.shorthand)\n this.adopt(sheets.longhand)\n }\n\n classFor(property: string, value: string): string {\n const key = `${property}:${value}`\n const known = this.classNames.get(key)\n if (known !== undefined) return known\n\n const className = `rn-${hash(key)}`\n this.classNames.set(key, className)\n\n const shorthand = shorthandProperties.has(property)\n const rule = `.${className}{${toKebab(property)}:${value}}`\n const rules = shorthand ? this.shorthandRules : this.longhandRules\n rules.push(rule)\n\n if (!this.adopted.has(className)) {\n const sheet = shorthand ? this.sheets.shorthand : this.sheets.longhand\n sheet?.insertRule(rule, sheet.cssRules.length)\n }\n return className\n }\n\n classesFor(declarations: CSSDeclarations): string {\n const names: string[] = []\n for (const property in declarations) {\n names.push(this.classFor(property, declarations[property] as string))\n }\n return names.join(' ')\n }\n\n // Inserts a fixed set of rules under one class name, once. For rules an atomic\n // declaration cannot express, for example a child selector.\n staticClass(className: string, rules: ReadonlyArray<string>): string {\n if (this.classNames.has(className)) return className\n this.classNames.set(className, className)\n for (const rule of rules) {\n this.longhandRules.push(rule)\n if (!this.adopted.has(className)) {\n const sheet = this.sheets.longhand\n sheet?.insertRule(rule, sheet.cssRules.length)\n }\n }\n return className\n }\n\n // The rules of each sheet, for server rendering.\n cssText(): { shorthand: string; longhand: string } {\n return { shorthand: this.shorthandRules.join('\\n'), longhand: this.longhandRules.join('\\n') }\n }\n\n get ruleCount(): number {\n return this.shorthandRules.length + this.longhandRules.length\n }\n\n // Remembers the class names the server already rendered, so the client does not insert them again.\n private adopt(sheet: CSSStyleSheet | null): void {\n if (sheet === null) return\n for (const rule of Array.from(sheet.cssRules)) {\n if (rule instanceof CSSStyleRule) this.adopted.add(rule.selectorText.slice(1))\n }\n }\n}\n\nlet defaultRegistry: StyleRegistry | null = null\n\nexport const getStyleRegistry = (): StyleRegistry => {\n if (defaultRegistry !== null) return defaultRegistry\n defaultRegistry = new StyleRegistry(\n hasDOM()\n ? { shorthand: domSheet(SHORTHAND_STYLE_ID), longhand: domSheet(LONGHAND_STYLE_ID) }\n : { shorthand: null, longhand: null },\n )\n return defaultRegistry\n}\n\n// For tests, so each file starts with an empty registry.\nexport const resetStyleRegistry = (): void => {\n defaultRegistry = null\n if (!hasDOM()) return\n document.getElementById(SHORTHAND_STYLE_ID)?.remove()\n document.getElementById(LONGHAND_STYLE_ID)?.remove()\n}\n\nconst domSheet = (id: string): CSSStyleSheet => {\n let element = document.getElementById(id) as HTMLStyleElement | null\n if (element === null) {\n element = document.createElement('style')\n element.id = id\n document.head.appendChild(element)\n }\n return element.sheet as CSSStyleSheet\n}\n","import { createContext, useContext, type Context } from 'react'\n\nimport { getStyleRegistry, type StyleRegistry } from './registry'\n\nexport const StyleRegistryContext: Context<StyleRegistry | null> =\n createContext<StyleRegistry | null>(null)\n\nexport const useStyleRegistry = (): StyleRegistry =>\n useContext(StyleRegistryContext) ?? getStyleRegistry()\n"],"mappings":";;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