Skip to content
31 changes: 25 additions & 6 deletions docs/usewindowdimensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const {height, width} = useWindowDimensions();
## Example

```SnackPlayer name=useWindowDimensions&supportedPlatforms=ios,android
import {StyleSheet, Text, useWindowDimensions} from 'react-native';
import {StyleSheet, Text, View, useWindowDimensions} from 'react-native';
import {SafeAreaView, SafeAreaProvider} from 'react-native-safe-area-context';

const App = () => {
Expand All @@ -25,23 +25,38 @@ const App = () => {
<SafeAreaProvider>
<SafeAreaView style={styles.container}>
<Text style={styles.header}>Window Dimension Data</Text>
<Text>Height: {height}</Text>
<Text>Width: {width}</Text>
<Text>Font scale: {fontScale}</Text>
<Text>Pixel ratio: {scale}</Text>
<View>
<Text>Height: {height}</Text>
<Text>Width: {width}</Text>
<Text>Font scale: {fontScale}</Text>
<Text>Pixel ratio: {scale}</Text>
</View>
<View
style={{
width: 100 * fontScale,
padding: 16 * fontScale,
...styles.box,
}}>
<Text style={{fontSize: 14 / fontScale}}>Dynamic Box</Text>
</View>
</SafeAreaView>
</SafeAreaProvider>
);
};

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
gap: 12,
},
header: {
fontSize: 20,
marginBottom: 12,
},
box: {
minWidth: 100,
backgroundColor: '#06bcee',
},
});

Expand All @@ -58,6 +73,10 @@ useWindowDimensions().fontScale;

The scale of the font currently used. Some operating systems allow users to scale their font sizes larger or smaller for reading comfort. This property will let you know what is in effect.

:::note
Changing the font size percentage can be leveraged to dynamically adjust the sizes of UI elements, such as padding, margins, and container heights, to ensure a consistent and accessible user experience. By using the fontScale property, developers can make their applications more adaptable to users' preferences for larger or smaller text, enhancing readability and usability.
:::

---

### `height`
Expand Down
Loading