Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/animated.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ For example, when working with horizontal scrolling gestures, you would do the f
x: scrollX
}
}
}]
}],
{useNativeEvent: true}
)}
```

Expand Down
17 changes: 10 additions & 7 deletions docs/animatedvaluexy.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ const DraggableView = () => {

const panResponder = PanResponder.create({
onStartShouldSetPanResponder: () => true,
onPanResponderMove: Animated.event([
null,
{
dx: pan.x, // x,y are Animated.Value
dy: pan.y,
},
]),
onPanResponderMove: Animated.event(
[
null,
{
dx: pan.x, // x,y are Animated.Value
dy: pan.y,
},
],
{useNativeDriver: false},
),
onPanResponderRelease: () => {
Animated.spring(
pan, // Auto-multiplexed
Expand Down
39 changes: 22 additions & 17 deletions docs/animations.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,15 @@ Gestures, like panning or scrolling, and other events can map directly to animat
For example, when working with horizontal scrolling gestures, you would do the following in order to map `event.nativeEvent.contentOffset.x` to `scrollX` (an `Animated.Value`):

```tsx
onScroll={Animated.event(
// scrollX = e.nativeEvent.contentOffset.x
[{nativeEvent: {
contentOffset: {
x: scrollX
}
}
}]
)}
onScroll={Animated.event(
// scrollX = e.nativeEvent.contentOffset.x
[{
nativeEvent: {
contentOffset: { x: scrollX }
}
}],
{useNativeDriver: true}
)}
```

The following example implements a horizontal scrolling carousel where the scroll position indicators are animated using the `Animated.event` used in the `ScrollView`
Expand Down Expand Up @@ -338,15 +338,18 @@ const App = () => {
horizontal={true}
pagingEnabled
showsHorizontalScrollIndicator={false}
onScroll={Animated.event([
{
nativeEvent: {
contentOffset: {
x: scrollX,
onScroll={Animated.event(
[
{
nativeEvent: {
contentOffset: {
x: scrollX,
},
},
},
},
])}
],
{useNativeDriver: true},
)}
scrollEventThrottle={1}>
{images.map((image, imageIndex) => {
return (
Expand Down Expand Up @@ -459,7 +462,9 @@ const App = () => {
const panResponder = useRef(
PanResponder.create({
onMoveShouldSetPanResponder: () => true,
onPanResponderMove: Animated.event([null, {dx: pan.x, dy: pan.y}]),
onPanResponderMove: Animated.event([null, {dx: pan.x, dy: pan.y}], {
useNativeDriver: false,
}),
onPanResponderRelease: () => {
Animated.spring(pan, {
toValue: {x: 0, y: 0},
Expand Down
2 changes: 1 addition & 1 deletion docs/appstate.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const AppStateExample = () => {
useEffect(() => {
const subscription = AppState.addEventListener('change', nextAppState => {
if (
appState.current.match(/inactive|background/) &&
appState.current?.match(/inactive|background/) &&
nextAppState === 'active'
) {
console.log('App has come to the foreground!');
Expand Down
15 changes: 11 additions & 4 deletions docs/dimensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ If you are targeting foldable devices or devices which can change the screen siz

## Example

```SnackPlayer name=Dimensions%20Example
```SnackPlayer name=Dimensions%20Example&ext=tsx
import {useState, useEffect} from 'react';
import {StyleSheet, Text, Dimensions} from 'react-native';
import {
StyleSheet,
Text,
Dimensions,
type DimensionsPayload,
} from 'react-native';
import {SafeAreaView, SafeAreaProvider} from 'react-native-safe-area-context';

const windowDimensions = Dimensions.get('window');
Expand All @@ -43,8 +48,10 @@ const App = () => {
useEffect(() => {
const subscription = Dimensions.addEventListener(
'change',
({window, screen}) => {
setDimensions({window, screen});
({window, screen}: DimensionsPayload) => {
if (window && screen) {
setDimensions({window, screen});
}
},
);
return () => subscription?.remove();
Expand Down
6 changes: 5 additions & 1 deletion docs/drawerlayoutandroid.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,12 @@ import {
View,
} from 'react-native';

type DrawerLayoutAndroidInstance = React.ComponentRef<
typeof DrawerLayoutAndroid
>;

const App = () => {
const drawer = useRef<DrawerLayoutAndroid>(null);
const drawer = useRef<DrawerLayoutAndroidInstance>(null);
const [drawerPosition, setDrawerPosition] = useState<'left' | 'right'>(
'left',
);
Expand Down
17 changes: 11 additions & 6 deletions docs/flexbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -1099,12 +1099,17 @@ export default AlignSelfLayout;

```SnackPlayer name=Align%20Self&ext=tsx
import {useState} from 'react';
import {View, TouchableOpacity, Text, StyleSheet} from 'react-native';
import {
View,
TouchableOpacity,
Text,
StyleSheet,
type ViewStyle,
} from 'react-native';
import type {PropsWithChildren} from 'react';
import type {FlexAlignType} from 'react-native';

const AlignSelfLayout = () => {
const [alignSelf, setAlignSelf] = useState<FlexAlignType>('stretch');
const [alignSelf, setAlignSelf] = useState<ViewStyle['alignSelf']>('stretch');

return (
<PreviewLayout
Expand All @@ -1131,9 +1136,9 @@ const AlignSelfLayout = () => {

type PreviewLayoutProps = PropsWithChildren<{
label: string;
values: FlexAlignType[];
selectedValue: string;
setSelectedValue: (value: FlexAlignType) => void;
values: ViewStyle['alignSelf'][];
selectedValue: ViewStyle['alignSelf'];
setSelectedValue: (value: ViewStyle['alignSelf']) => void;
}>;

const PreviewLayout = ({
Expand Down
8 changes: 6 additions & 2 deletions docs/improvingux.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ import {
StyleSheet,
} from 'react-native';

type TextInputInstance = React.ComponentRef<typeof TextInput>;

const App = () => {
const emailInput = useRef<TextInput>(null);
const emailInput = useRef<TextInputInstance>(null);
const [name, setName] = useState('');
const [email, setEmail] = useState('');

Expand Down Expand Up @@ -325,8 +327,10 @@ import {
StyleSheet,
} from 'react-native';

type TextInputInstance = React.ComponentRef<typeof TextInput>;

const App = () => {
const emailInput = useRef<TextInput>(null);
const emailInput = useRef<TextInputInstance>(null);
const [email, setEmail] = useState('');

const submit = () => {
Expand Down
21 changes: 10 additions & 11 deletions docs/layout-props.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ import {
StyleSheet,
Text,
View,
FlexAlignType,
FlexStyle,
ViewStyle,
} from 'react-native';
import {SafeAreaView, SafeAreaProvider} from 'react-native-safe-area-context';

Expand All @@ -217,7 +216,7 @@ const App = () => {
alignItems: alignItemsArr[alignItems],
direction: directions[direction],
flexWrap: wraps[wrap],
} as FlexStyle;
};

const changeSetting = (
value: number,
Expand Down Expand Up @@ -307,29 +306,29 @@ const App = () => {
);
};

const flexDirections = [
const flexDirections: ViewStyle['flexDirection'][] = [
'row',
'row-reverse',
'column',
'column-reverse',
] as FlexStyle['flexDirection'][];
const justifyContents = [
];
const justifyContents: ViewStyle['justifyContent'][] = [
'flex-start',
'flex-end',
'center',
'space-between',
'space-around',
'space-evenly',
] as FlexStyle['justifyContent'][];
const alignItemsArr = [
];
const alignItemsArr: ViewStyle['alignItems'][] = [
'flex-start',
'flex-end',
'center',
'stretch',
'baseline',
] as FlexAlignType[];
const wraps = ['nowrap', 'wrap', 'wrap-reverse'];
const directions = ['inherit', 'ltr', 'rtl'];
];
const wraps: ViewStyle['flexWrap'][] = ['nowrap', 'wrap', 'wrap-reverse'];
const directions: ViewStyle['direction'][] = ['inherit', 'ltr', 'rtl'];

const styles = StyleSheet.create({
container: {
Expand Down
25 changes: 16 additions & 9 deletions docs/legacy/direct-manipulation.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,16 @@ export default App;
<TabItem value="typescript">

```SnackPlayer name=Forwarding%20setNativeProps&ext=tsx
import {forwardRef} from 'react';
import {forwardRef, ElementRef} from 'react';
import {Text, TouchableOpacity, View} from 'react-native';

const MyButton = forwardRef<View, {label: string}>((props, ref) => (
<View {...props} ref={ref} style={{marginTop: 50}}>
<Text>{props.label}</Text>
</View>
));
const MyButton = forwardRef<ElementRef<typeof View>, {label: string}>(
(props, ref) => (
<View {...props} ref={ref} style={{marginTop: 50}}>
<Text>{props.label}</Text>
</View>
),
);

const App = () => (
<TouchableOpacity>
Expand Down Expand Up @@ -229,8 +231,10 @@ import {
View,
} from 'react-native';

type TextInputInstance = React.ComponentRef<typeof TextInput>;

const App = () => {
const inputRef = useRef<TextInput>(null);
const inputRef = useRef<TextInputInstance>(null);
const editText = useCallback(() => {
inputRef.current?.setNativeProps({text: 'Edited Text'});
}, []);
Expand Down Expand Up @@ -379,9 +383,12 @@ type Measurements = {
height: number;
};

type TextInstance = React.ComponentRef<typeof Text>;
type ViewInstance = React.ComponentRef<typeof View>;

const App = () => {
const textContainerRef = useRef<View>(null);
const textRef = useRef<Text>(null);
const textContainerRef = useRef<ViewInstance>(null);
const textRef = useRef<TextInstance>(null);
const [measure, setMeasure] = useState<Measurements | null>(null);

useEffect(() => {
Expand Down
4 changes: 2 additions & 2 deletions docs/linking.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ const useInitialURL = () => {

// The setTimeout is just for testing purpose
setTimeout(() => {
setUrl(initialUrl);
setUrl(initialUrl ?? null);
setProcessing(false);
}, 1000);
};
Expand Down Expand Up @@ -390,7 +390,7 @@ const useInitialURL = () => {

// The setTimeout is just for testing purpose
setTimeout(() => {
setUrl(initialUrl);
setUrl(initialUrl ?? null);
setProcessing(false);
}, 1000);
};
Expand Down
4 changes: 3 additions & 1 deletion docs/panresponder.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ const App = () => {
const panResponder = useRef(
PanResponder.create({
onMoveShouldSetPanResponder: () => true,
onPanResponderMove: Animated.event([null, {dx: pan.x, dy: pan.y}]),
onPanResponderMove: Animated.event([null, {dx: pan.x, dy: pan.y}], {
useNativeDriver: false,
}),
onPanResponderRelease: () => {
pan.extractOffset();
},
Expand Down
10 changes: 7 additions & 3 deletions docs/progressbarandroid.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@ const App = () => {
<View style={styles.container}>
<View style={styles.example}>
<Text>Circle Progress Indicator</Text>
<ProgressBarAndroid />
<ProgressBarAndroid indeterminate styleAttr="Normal" />
</View>
<View style={styles.example}>
<Text>Horizontal Progress Indicator</Text>
<ProgressBarAndroid styleAttr="Horizontal" />
<ProgressBarAndroid indeterminate styleAttr="Horizontal" />
</View>
<View style={styles.example}>
<Text>Colored Progress Indicator</Text>
<ProgressBarAndroid styleAttr="Horizontal" color="#2196F3" />
<ProgressBarAndroid
indeterminate
styleAttr="Horizontal"
color="#2196F3"
/>
</View>
<View style={styles.example}>
<Text>Fixed Progress Value</Text>
Expand Down
15 changes: 8 additions & 7 deletions docs/statusbar.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
} from 'react-native';
import {SafeAreaView, SafeAreaProvider} from 'react-native-safe-area-context';

const STYLES = ['default', 'dark-content', 'light-content'];
const STYLES = ['default', 'auto', 'dark-content', 'light-content'];
const TRANSITIONS = ['fade', 'slide', 'none'];

const App = () => {
Expand Down Expand Up @@ -134,7 +134,7 @@ import {
} from 'react-native';
import {SafeAreaView, SafeAreaProvider} from 'react-native-safe-area-context';

const STYLES = ['default', 'dark-content', 'light-content'] as const;
const STYLES = ['default', 'auto', 'dark-content', 'light-content'] as const;
const TRANSITIONS = ['fade', 'slide', 'none'] as const;

const App = () => {
Expand Down Expand Up @@ -407,8 +407,9 @@ Status bar style type.

**Constants:**

| Value | Type | Description |
| ----------------- | ------ | ---------------------------------------------------------- |
| `'default'` | string | Default status bar style (dark for iOS, light for Android) |
| `'light-content'` | string | White texts and icons |
| `'dark-content'` | string | Dark texts and icons (requires API>=23 on Android) |
| Value | Type | Description |
| ----------------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------- |
| `'default'` | string | Default status bar style (light for Android, dark for iOS) |
| `'auto'` | string | Automatically picks `light-content` or `dark-content` based on the current color scheme. Updates whenever the color scheme changes. |
| `'light-content'` | string | White texts and icons |
| `'dark-content'` | string | Dark texts and icons (requires API>=23 on Android) |
Loading