Update interactive examples

This commit is contained in:
Nicolas Gallagher
2023-04-11 16:22:59 -07:00
parent 338cce194d
commit 3e74ed0ea7
16 changed files with 113 additions and 84 deletions
@@ -8,5 +8,9 @@ const pages = fs
module.exports = { module.exports = {
outDir: 'dist', outDir: 'dist',
env: { pages } env: { pages },
webpack: (config, options) => {
config.resolve.alias['react-native'] = 'react-native-web';
return config;
}
}; };
@@ -1,5 +1,6 @@
import { Button, Clipboard, StyleSheet, TextInput, View } from 'react-native'; import { Clipboard, StyleSheet, TextInput, View } from 'react-native';
import React from 'react'; import React from 'react';
import Button from '../../shared/button';
import Example from '../../shared/example'; import Example from '../../shared/example';
export default function ClipboardPage() { export default function ClipboardPage() {
+6 -3
View File
@@ -47,7 +47,11 @@ export default function ImagePage() {
<View style={styles.row}> <View style={styles.row}>
<View style={styles.column}> <View style={styles.column}>
<Text style={styles.text}>Static image</Text> <Text style={styles.text}>Static image</Text>
<Image source={'/image/ladybug.jpg'} style={styles.image} /> <Image
resizeMode="cover"
source={'/image/ladybug.jpg'}
style={styles.image}
/>
</View> </View>
<View style={styles.column}> <View style={styles.column}>
<Text style={styles.text}>Progressive JPEG</Text> <Text style={styles.text}>Progressive JPEG</Text>
@@ -143,8 +147,7 @@ const styles = StyleSheet.create({
borderColor: 'black', borderColor: 'black',
borderWidth: 0.5, borderWidth: 0.5,
height: 120, height: 120,
width: 120, width: 120
resizeMode: 'cover'
}, },
resizeMode: { resizeMode: {
borderColor: 'black', borderColor: 'black',
+4 -8
View File
@@ -8,11 +8,7 @@ const logoUri =
function Link(props) { function Link(props) {
return ( return (
<NextLink href={props.href}> <NextLink href={props.href}>
<Text <Text {...props} role="link" style={[styles.link, props.style]} />
{...props}
accessibilityRole="link"
style={[styles.link, props.style]}
/>
</NextLink> </NextLink>
); );
} }
@@ -22,7 +18,7 @@ export default function IndexPage() {
<View style={styles.app}> <View style={styles.app}>
<View style={styles.header}> <View style={styles.header}>
<Image <Image
accessibilityLabel="React logo" aria-label="React logo"
resizeMode="contain" resizeMode="contain"
source={{ uri: logoUri }} source={{ uri: logoUri }}
style={styles.logo} style={styles.logo}
@@ -36,9 +32,9 @@ export default function IndexPage() {
example app built on Next.js example app built on Next.js
</Text> </Text>
<View accessibilityRole="list"> <View role="list">
{process.env.pages.map((name) => ( {process.env.pages.map((name) => (
<View accessibilityRole="listitem" key={name} style={styles.listitem}> <View key={name} role="listitem" style={styles.listitem}>
<Link href={'/' + name} style={styles.pageLink}> <Link href={'/' + name} style={styles.pageLink}>
{name} {name}
</Link> </Link>
+1 -1
View File
@@ -18,11 +18,11 @@ export default class LinkingPage extends PureComponent {
Linking.openURL Linking.openURL
</Text> </Text>
<Text <Text
accessibilityRole="link"
href="https://mathiasbynens.github.io/rel-noopener/malicious.html" href="https://mathiasbynens.github.io/rel-noopener/malicious.html"
hrefAttrs={{ hrefAttrs={{
target: '_blank' target: '_blank'
}} }}
role="link"
style={styles.text} style={styles.text}
> >
target="_blank" target="_blank"
+14 -23
View File
@@ -15,7 +15,7 @@ import {
Image, Image,
StyleSheet, StyleSheet,
Switch, Switch,
TouchableHighlight, Pressable,
Text, Text,
TextInput, TextInput,
View View
@@ -92,14 +92,11 @@ class ItemComponent extends React.PureComponent<{
const itemHash = Math.abs(hashCode(item.title)); const itemHash = Math.abs(hashCode(item.title));
const imgSource = THUMB_URLS[itemHash % THUMB_URLS.length]; const imgSource = THUMB_URLS[itemHash % THUMB_URLS.length];
return ( return (
<TouchableHighlight <Pressable
onHideUnderlay={this.props.onHideUnderlay}
onPress={this._onPress} onPress={this._onPress}
onShowUnderlay={this.props.onShowUnderlay} onPressIn={this.props.onShowUnderlay}
onPressOut={this.props.onHideUnderlay}
style={horizontal ? styles.horizItem : styles.item} style={horizontal ? styles.horizItem : styles.item}
tvParallaxProperties={{
pressMagnification: 1.1
}}
> >
<View <View
style={[ style={[
@@ -116,7 +113,7 @@ class ItemComponent extends React.PureComponent<{
{item.title} - {item.text} {item.title} - {item.text}
</Text> </Text>
</View> </View>
</TouchableHighlight> </Pressable>
); );
} }
} }
@@ -172,15 +169,11 @@ class Spindicator extends React.PureComponent<{}> {
style={[ style={[
styles.spindicator, styles.spindicator,
{ {
transform: [ rotate: this.props.value.interpolate({
{ inputRange: [0, 5000],
rotate: this.props.value.interpolate({ outputRange: ['0deg', '360deg'],
inputRange: [0, 5000], extrapolate: 'extend'
outputRange: ['0deg', '360deg'], })
extrapolate: 'extend'
})
}
]
} }
]} ]}
/> />
@@ -263,9 +256,7 @@ class SingleColumnExample extends React.PureComponent {
}; };
_onChangeScrollToIndex = (text) => { _onChangeScrollToIndex = (text) => {
this._listRef this._listRef.scrollToIndex({ viewPosition: 0.5, index: Number(text) });
.getNode()
.scrollToIndex({ viewPosition: 0.5, index: Number(text) });
}; };
_scrollPos = new Animated.Value(0); _scrollPos = new Animated.Value(0);
@@ -283,7 +274,7 @@ class SingleColumnExample extends React.PureComponent {
); );
componentDidUpdate() { componentDidUpdate() {
this._listRef.getNode().recordInteraction(); // e.g. flipping logViewable switch this._listRef.recordInteraction(); // e.g. flipping logViewable switch
} }
render() { render() {
@@ -398,7 +389,7 @@ class SingleColumnExample extends React.PureComponent {
} }
}; };
_pressItem = (key: string) => { _pressItem = (key: string) => {
this._listRef.getNode().recordInteraction(); this._listRef.recordInteraction();
pressItem(this, key); pressItem(this, key);
}; };
_listRef: AnimatedFlatList; _listRef: AnimatedFlatList;
@@ -469,7 +460,7 @@ const styles = StyleSheet.create({
smallSwitch: { smallSwitch: {
top: 1, top: 1,
margin: -6, margin: -6,
transform: [{ scale: 0.7 }] transform: 'scale(0.7)'
}, },
stacked: { stacked: {
alignItems: 'center', alignItems: 'center',
@@ -12,9 +12,9 @@
import React from 'react'; import React from 'react';
import { import {
Button,
Image, Image,
PixelRatio, PixelRatio,
Pressable,
ScrollView, ScrollView,
StyleSheet, StyleSheet,
Text, Text,
@@ -41,7 +41,9 @@ function ListItem(props) {
</View> </View>
</View> </View>
<View style={styles.column3}> <View style={styles.column3}>
<Button onPress={() => {}} style={styles.smallButton} title="Button" /> <Pressable onPress={() => {}} style={styles.smallButton}>
<Text>Button</Text>
</Pressable>
</View> </View>
</View> </View>
); );
@@ -88,12 +90,13 @@ function withRTLState(Component) {
const RTLToggler = ({ isRTL, setRTL }) => { const RTLToggler = ({ isRTL, setRTL }) => {
const toggleRTL = () => setRTL(!isRTL); const toggleRTL = () => setRTL(!isRTL);
return ( return (
<Button <Pressable
accessibilityLabel="Change layout direction" aria-label="Change layout direction"
color="gray" color="gray"
onPress={toggleRTL} onPress={toggleRTL}
title={isRTL ? 'RTL' : 'LTR'} >
/> <Text>{isRTL ? 'RTL' : 'LTR'}</Text>
</Pressable>
); );
}; };
+2 -1
View File
@@ -1,5 +1,6 @@
import React, { useState, useMemo } from 'react'; import React, { useState, useMemo } from 'react';
import { Modal, View, Text, Button, StyleSheet } from 'react-native'; import { Modal, View, Text, StyleSheet } from 'react-native';
import Button from '../../shared/button';
import Example from '../../shared/example'; import Example from '../../shared/example';
function Gap() { function Gap() {
@@ -121,7 +121,7 @@ class LocationXY extends React.Component {
}; };
render() { render() {
const transform = { transform: `translateX${this.state.translateX}` }; const transform = { transform: `translateX(${this.state.translateX}px)` };
return ( return (
<View style={styles.box}> <View style={styles.box}>
<View style={styles.outer} {...this.panResponder.panHandlers}> <View style={styles.outer} {...this.panResponder.panHandlers}>
@@ -1,12 +1,6 @@
import React from 'react'; import React from 'react';
import { import { ScrollView, StyleSheet, View, Text, Pressable } from 'react-native';
Button, import Button from '../../shared/button';
ScrollView,
StyleSheet,
View,
Text,
Pressable
} from 'react-native';
import Example from '../../shared/example'; import Example from '../../shared/example';
export default function PressablePage() { export default function PressablePage() {
@@ -29,7 +23,6 @@ export default function PressablePage() {
<Example title="Pressable"> <Example title="Pressable">
<View style={styles.container}> <View style={styles.container}>
<Pressable <Pressable
accessibilityRole="button"
delayLongPress="750" delayLongPress="750"
delayPressIn={delay} delayPressIn={delay}
delayPressOut={delay} delayPressOut={delay}
@@ -45,6 +38,7 @@ export default function PressablePage() {
onPress={handleEvent(`onPress - ${delay}ms delay`)} onPress={handleEvent(`onPress - ${delay}ms delay`)}
onPressIn={handleEvent(`onPressIn - ${delay}ms delay`)} onPressIn={handleEvent(`onPressIn - ${delay}ms delay`)}
onPressOut={handleEvent(`oPressOut - ${delay}ms delay`)} onPressOut={handleEvent(`oPressOut - ${delay}ms delay`)}
role="button"
style={(state) => [ style={(state) => [
styles.pressable, styles.pressable,
!disabled && state.focused && styles.focused, !disabled && state.focused && styles.focused,
@@ -1,12 +1,6 @@
import React from 'react'; import React from 'react';
import { import { ScrollView, StyleSheet, Text, Pressable, View } from 'react-native';
Button, import Button from '../../shared/button';
ScrollView,
StyleSheet,
Text,
Pressable,
View
} from 'react-native';
import Example from '../../shared/example'; import Example from '../../shared/example';
const ITEMS = [...Array(12)].map((_, i) => `Item ${i}`); const ITEMS = [...Array(12)].map((_, i) => `Item ${i}`);
@@ -39,13 +39,13 @@ export default function TextInputPage() {
style={styles.textinput} style={styles.textinput}
/> />
<TextInput <TextInput
defaultValue="editable (false)" defaultValue="readOnly (true)"
editable={false} readOnly={true}
style={styles.textinput} style={styles.textinput}
/> />
<TextInput <TextInput
keyboardType="numeric" inputMode="numeric"
placeholder="keyboardType 'numeric'" placeholder="inputMode 'numeric'"
style={styles.textinput} style={styles.textinput}
/> />
<TextInput <TextInput
@@ -71,8 +71,8 @@ export default function TextInputPage() {
/> />
<TextInput <TextInput
multiline={true} multiline={true}
numberOfLines={3}
placeholder="multiline" placeholder="multiline"
rows={3}
style={styles.multiline} style={styles.multiline}
/> />
</View> </View>
+10 -9
View File
@@ -6,8 +6,8 @@ const Spacer = () => <View style={{ height: '1rem' }} />;
const Heading = ({ children }) => ( const Heading = ({ children }) => (
<Text <Text
accessibilityRole="heading"
children={children} children={children}
role="heading"
style={{ fontSize: '1rem', fontWeight: 'bold', marginBottom: '0.5rem' }} style={{ fontSize: '1rem', fontWeight: 'bold', marginBottom: '0.5rem' }}
/> />
); );
@@ -298,9 +298,7 @@ function TextShadow() {
<Text <Text
style={{ style={{
fontSize: 20, fontSize: 20,
textShadowOffset: { width: 2, height: 2 }, textShadow: '2px 2px 1px #00cccc'
textShadowRadius: 1,
textShadowColor: '#00cccc'
}} }}
> >
Text shadow example Text shadow example
@@ -383,8 +381,9 @@ export default function TextPage() {
/>{' '} />{' '}
and an inline image{' '} and an inline image{' '}
<Image <Image
resizeMode="cover"
source={{ uri: 'http://lorempixel.com/30/11' }} source={{ uri: 'http://lorempixel.com/30/11' }}
style={{ width: 30, height: 11, resizeMode: 'cover' }} style={{ width: 30, height: 11 }}
/> />
. .
</Text> </Text>
@@ -412,14 +411,16 @@ export default function TextPage() {
And then continues as text. And then continues as text.
</Text> </Text>
<Text selectable={true}> <Text>
This text is <Text style={{ fontWeight: 'bold' }}>selectable</Text> if This text is <Text style={{ fontWeight: 'bold' }}>selectable</Text> if
you click-and-hold. you click-and-hold.
</Text> </Text>
<Text selectable={false}> <Text>
This text is{' '} This text is{' '}
<Text style={{ fontWeight: 'bold' }}>not selectable</Text> if you <Text style={{ fontWeight: 'bold', userSelect: 'none' }}>
click-and-hold. not selectable
</Text>{' '}
if you click-and-hold.
</Text> </Text>
<View style={{ paddingVertical: 20 }}> <View style={{ paddingVertical: 20 }}>
+24 -6
View File
@@ -13,8 +13,11 @@ function Box({ pointerEvents }) {
return ( return (
<Pressable <Pressable
onPress={log} onPress={log}
pointerEvents={pointerEvents} style={({ pressed }) => [
style={({ pressed }) => [styles.box, pressed && styles.purple]} styles.box,
pressed && styles.purple,
pointerEventsStyles[pointerEvents]
]}
> >
<Pressable <Pressable
onPress={log} onPress={log}
@@ -46,7 +49,7 @@ export default function ViewPage() {
return ( return (
<Example title="View"> <Example title="View">
<View style={styles.container}> <View style={styles.container}>
<Text accessibilityRole="heading" style={styles.heading}> <Text role="heading" style={styles.heading}>
onLayout onLayout
</Text> </Text>
<View> <View>
@@ -56,11 +59,11 @@ export default function ViewPage() {
<Text>{JSON.stringify(layoutInfo, null, 2)}</Text> <Text>{JSON.stringify(layoutInfo, null, 2)}</Text>
</View> </View>
<Text accessibilityRole="heading" style={styles.heading}> <Text role="heading" style={styles.heading}>
pointerEvents pointerEvents
</Text> </Text>
<View pointerEvents="box-none"> <View style={pointerEventsStyles['box-none']}>
<View pointerEvents="box-none" style={styles.boxContainer}> <View style={[styles.boxContainer, pointerEventsStyles['box-none']]}>
<Box pointerEvents="none" /> <Box pointerEvents="none" />
<Box pointerEvents="auto" /> <Box pointerEvents="auto" />
<Box pointerEvents="box-only" /> <Box pointerEvents="box-only" />
@@ -112,3 +115,18 @@ const styles = StyleSheet.create({
backgroundColor: 'purple' backgroundColor: 'purple'
} }
}); });
const pointerEventsStyles = StyleSheet.create({
auto: {
pointerEvents: 'auto'
},
none: {
pointerEvents: 'none'
},
'box-only': {
pointerEvents: 'box-only'
},
'box-none': {
pointerEvents: 'box-none'
}
});
+23
View File
@@ -0,0 +1,23 @@
import { StyleSheet, Text, Pressable } from 'react-native';
export default function Button(props) {
const { title, ...other } = props;
return (
<Pressable {...other} style={styles.button}>
<Text style={styles.buttonText}>{title}</Text>
</Pressable>
);
}
const styles = StyleSheet.create({
button: {
backgroundColor: 'lightblue',
borderRadius: 10,
paddingBlock: 5,
paddingInline: 10
},
buttonText: {
fontWeight: 'bold',
textTransform: 'uppercase'
}
});
+2 -2
View File
@@ -4,7 +4,7 @@ export default function Example(props) {
return ( return (
<View style={styles.root}> <View style={styles.root}>
<View style={styles.header}> <View style={styles.header}>
<Text accessibilityLabel="Back" href="/" style={styles.back}> <Text aria-label="Back" href="/" style={styles.back}>
<svg <svg
style={{ fill: '#555', height: '100%' }} style={{ fill: '#555', height: '100%' }}
viewBox="0 0 140 140" viewBox="0 0 140 140"
@@ -13,7 +13,7 @@ export default function Example(props) {
<path d="M105.614 118.681c3.398 3.396 3.4 8.912 0 12.311-3.396 3.399-8.91 3.398-12.311 0-.02-.02-.035-.04-.053-.061l-.025.022-57.66-57.66.024-.022a8.664 8.664 0 01-2.608-6.208 8.672 8.672 0 013.229-6.762l-.06-.058 57.66-57.66.025.024c.018-.021.033-.039.053-.058A8.706 8.706 0 01106.2 14.86c-.021.02-.041.034-.061.054l.023.024-52.119 52.125 51.54 51.54-.025.021c.015.022.036.036.056.057" /> <path d="M105.614 118.681c3.398 3.396 3.4 8.912 0 12.311-3.396 3.399-8.91 3.398-12.311 0-.02-.02-.035-.04-.053-.061l-.025.022-57.66-57.66.024-.022a8.664 8.664 0 01-2.608-6.208 8.672 8.672 0 013.229-6.762l-.06-.058 57.66-57.66.025.024c.018-.021.033-.039.053-.058A8.706 8.706 0 01106.2 14.86c-.021.02-.041.034-.061.054l.023.024-52.119 52.125 51.54 51.54-.025.021c.015.022.036.036.056.057" />
</svg> </svg>
</Text> </Text>
<Text accessibilityRole="heading" style={styles.title}> <Text role="heading" style={styles.title}>
{props.title} {props.title}
</Text> </Text>
</View> </View>