React Native for Web is a comprehensive compatibility library that enables React Native components and APIs to run seamlessly on web browsers using React DOM.
npx @tessl/cli install tessl/npm-react-native-web@0.21.0React Native for Web is a comprehensive compatibility library that enables React Native components and APIs to run seamlessly on web browsers using React DOM. It provides a complete mapping of React Native's component system, styling capabilities, and platform APIs to web-equivalent implementations, allowing developers to write cross-platform applications using a single React Native codebase that works across mobile and web platforms.
npm install react-native-webimport { View, Text, StyleSheet, AppRegistry } from "react-native-web";For specific components:
import { Pressable, Image, ScrollView } from "react-native-web";CommonJS:
const { View, Text, StyleSheet } = require("react-native-web");import React from "react";
import { View, Text, StyleSheet, AppRegistry } from "react-native-web";
const App = () => (
<View style={styles.container}>
<Text style={styles.title}>Hello React Native Web!</Text>
</View>
);
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#f5f5f5",
},
title: {
fontSize: 24,
fontWeight: "bold",
color: "#333",
},
});
AppRegistry.registerComponent("App", () => App);
AppRegistry.runApplication("App", {
rootTag: document.getElementById("root"),
});React Native Web is built around several core concepts:
Essential utilities for rendering, element creation, and DOM integration. These provide the foundation for React Native Web's compatibility layer.
function render(element: React.Element, container: DOMContainer, callback?: Function): void;
function findNodeHandle(componentOrHandle: any): number | null;
function processColor(color: ColorValue): string | null;
function unstable_createElement(type: string, props?: Object, ...children: any[]): React.Element;
function unmountComponentAtNode(container: DOMContainer): boolean;Fundamental layout and container components including View, ScrollView, SafeAreaView, and Modal. These provide the structural foundation for React Native Web applications.
const View: React.ComponentType<ViewProps>;
const ScrollView: React.ComponentType<ScrollViewProps>;
const SafeAreaView: React.ComponentType<SafeAreaViewProps>;
const Modal: React.ComponentType<ModalProps>;
const KeyboardAvoidingView: React.ComponentType<KeyboardAvoidingViewProps>;Text display and input components with advanced typography, accessibility, and internationalization support.
const Text: React.ComponentType<TextProps>;
const TextInput: React.ComponentType<TextInputProps>;User interaction components including buttons, touchables, and pressable elements with comprehensive gesture and accessibility support.
const Button: React.ComponentType<ButtonProps>;
const Pressable: React.ComponentType<PressableProps>;
const TouchableOpacity: React.ComponentType<TouchableOpacityProps>;
const TouchableHighlight: React.ComponentType<TouchableHighlightProps>;
const TouchableWithoutFeedback: React.ComponentType<TouchableWithoutFeedbackProps>;Image display and media components with support for multiple source formats, caching, and accessibility.
const Image: React.ComponentType<ImageProps>;
const ImageBackground: React.ComponentType<ImageBackgroundProps>;Form input components including switches, checkboxes, pickers, and progress indicators.
const Switch: React.ComponentType<SwitchProps>;
const CheckBox: React.ComponentType<CheckBoxProps>;
const Picker: React.ComponentType<PickerProps>;
const ProgressBar: React.ComponentType<ProgressBarProps>;
const ActivityIndicator: React.ComponentType<ActivityIndicatorProps>;High-performance list and virtualization components for handling large datasets efficiently.
const FlatList: React.ComponentType<FlatListProps>;
const SectionList: React.ComponentType<SectionListProps>;
const VirtualizedList: React.ComponentType<VirtualizedListProps>;
const RefreshControl: React.ComponentType<RefreshControlProps>;React Native's platform APIs adapted for web environments, including device information, status bar control, system services, and web integrations.
const Platform: {
OS: 'web';
Version: string;
isTesting: boolean;
select: <T>(specifics: {web?: T, default?: T}) => T;
};
const StatusBar: React.ComponentType<StatusBarProps> & {
setBackgroundColor: (color: string, animated?: boolean) => void;
setBarStyle: (style: 'default' | 'light-content' | 'dark-content', animated?: boolean) => void;
setHidden: (hidden: boolean, animation?: 'none' | 'fade' | 'slide') => void;
};
const Dimensions: {
get: (dim: 'window' | 'screen') => {width: number, height: number, scale: number, fontScale: number};
addEventListener: (type: 'change', listener: Function) => void;
removeEventListener: (type: 'change', listener: Function) => void;
};Advanced styling system with atomic CSS compilation, RTL support, and performance optimizations.
const StyleSheet: {
create: <T>(styles: T) => T;
compose: (style1: any, style2: any) => any;
flatten: (style: any) => Object;
absoluteFillObject: {position: 'absolute', left: 0, right: 0, top: 0, bottom: 0};
hairlineWidth: number;
};Comprehensive animation system with timing functions, easing curves, animated values, and component integration.
const Animated: {
View: React.ComponentType<AnimatedViewProps>;
Text: React.ComponentType<AnimatedTextProps>;
Image: React.ComponentType<AnimatedImageProps>;
ScrollView: React.ComponentType<AnimatedScrollViewProps>;
timing: (value: AnimatedValue, config: TimingAnimationConfig) => CompositeAnimation;
spring: (value: AnimatedValue, config: SpringAnimationConfig) => CompositeAnimation;
decay: (value: AnimatedValue, config: DecayAnimationConfig) => CompositeAnimation;
Value: typeof AnimatedValue;
ValueXY: typeof AnimatedValueXY;
};
const Easing: {
linear: (t: number) => number;
ease: (t: number) => number;
bezier: (x1: number, y1: number, x2: number, y2: number) => (t: number) => number;
bounce: (t: number) => number;
elastic: (bounciness?: number) => (t: number) => number;
in: (easing: (t: number) => number) => (t: number) => number;
out: (easing: (t: number) => number) => (t: number) => number;
inOut: (easing: (t: number) => number) => (t: number) => number;
};APIs for integrating with browser and system features including application lifecycle, theme detection, clipboard, linking, alerts, and sharing.
const AppRegistry: {
registerComponent: (appKey: string, componentProvider: () => React.ComponentType) => string;
runApplication: (appKey: string, appParameters: AppParameters) => void;
getAppKeys: () => string[];
};
const Appearance: {
getColorScheme: () => 'light' | 'dark';
addChangeListener: (listener: (preferences: AppearancePreferences) => void) => {remove: () => void};
};
const Alert: {
alert: (title: string, message?: string, buttons?: AlertButton[], options?: AlertOptions) => void;
};
const Clipboard: {
getString: () => Promise<string>;
setString: (content: string) => void;
hasString: () => Promise<boolean>;
};
const Linking: {
openURL: (url: string) => Promise<void>;
canOpenURL: (url: string) => Promise<boolean>;
getInitialURL: () => Promise<string | null>;
};Comprehensive accessibility features and screen reader support for inclusive applications.
const AccessibilityInfo: {
announceForAccessibility: (announcement: string) => void;
isScreenReaderEnabled: () => Promise<boolean>;
isBoldTextEnabled: () => Promise<boolean>;
isGrayscaleEnabled: () => Promise<boolean>;
isInvertColorsEnabled: () => Promise<boolean>;
isReduceMotionEnabled: () => Promise<boolean>;
isReduceTransparencyEnabled: () => Promise<boolean>;
setAccessibilityFocus: (reactTag: number) => void;
};React hooks for common React Native Web functionality including dimensions, color scheme, and locale context.
function useWindowDimensions(): {width: number, height: number, scale: number, fontScale: number};
function useColorScheme(): 'light' | 'dark' | null;
function useLocaleContext(): {direction: 'ltr' | 'rtl', locale: string};type ColorValue = string | null;
type DimensionValue = number | string | null;
interface EdgeInsetsValue {
top: number;
left: number;
right: number;
bottom: number;
}
interface LayoutValue {
x: number;
y: number;
width: number;
height: number;
}
interface LayoutEvent {
nativeEvent: {
layout: LayoutValue;
target: any;
};
timeStamp: number;
}
interface PointValue {
x: number;
y: number;
}
interface PlatformMethods {
blur(): void;
focus(): void;
measure(callback: (x: number, y: number, width: number, height: number, pageX: number, pageY: number) => void): void;
measureInWindow(callback: (x: number, y: number, width: number, height: number) => void): void;
measureLayout(
relativeToNativeNode: any,
onSuccess: (x: number, y: number, width: number, height: number, pageX: number, pageY: number) => void,
onFail: () => void
): void;
}