/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @flow strict-local * @format */ 'use strict'; import type {RNTesterModuleExample} from '../../types/RNTesterTypes'; import RNTesterText from '../../components/RNTesterText'; import {RNTesterThemeContext} from '../../components/RNTesterTheme'; import * as React from 'react'; import {useContext, useState} from 'react'; import {Button, PixelRatio, StyleSheet, TextInput, View} from 'react-native'; function LayoutSizeToPixel() { const theme = useContext(RNTesterThemeContext); const [layoutDPSize, setLayoutDPSize] = useState(0); const pixelSize = PixelRatio.getPixelSizeForLayoutSize( layoutDPSize ? layoutDPSize : 0, ); const handleDPInputChange = (changedText: string) => { const layoutSize = parseInt(changedText, 10); setLayoutDPSize(layoutSize); }; return ( Layout Size(dp):{' '} Pixel Size: {pixelSize}px ); } function RoundToNearestPixel() { const theme = useContext(RNTesterThemeContext); const [layoutDPSizeText, setLayoutDPSizeText] = useState(''); const layoutDPSize = parseFloat(layoutDPSizeText); const pixelSize = PixelRatio.roundToNearestPixel( layoutDPSize ? layoutDPSize : 0, ); const handleDPInputChange = (changedText: string) => { setLayoutDPSizeText(changedText); }; return ( Layout Size(dp):{' '} Nearest Layout Size:{' '} {pixelSize}dp ); } function GetPixelRatio() { const [pixelDensity, setPixelDensity] = useState(0); const getPixelDensityCallback = () => { setPixelDensity(PixelRatio.get()); }; return (