عمر سالم2 نشر 22 مارس 2021 أرسل تقرير مشاركة نشر 22 مارس 2021 كيف أحصل على حجم View موجود في التطبيق؟ حاولت استخدام Dimensions ولكنها لم تعمل؟ function App() { const viewRef = useRef(null); const computeSize = event => { console.log(viewRef.style.width, viewRef.style.height); }; return ( <View ref={viewRef}> <Button title="Get Size" onPress={computeSize} /> </View> ); } اقتباس رابط هذا التعليق شارك على الشبكات الإجتماعية More sharing options...
0 إسلام عبدالعزيز نشر 23 مارس 2021 أرسل تقرير مشاركة نشر 23 مارس 2021 يمكنك استخدام الخاصية "onLayout" حيث يتم استدعاؤها عند تركيب المكون وعند كل تغيير. import * as React from 'react'; import { Text, View, StyleSheet } from 'react-native'; export default function App() { const [dimensions, setDimensions] = React.useState({ width: 0, height: 0 }); const computeSize = event => { setDimensions({ width: event.nativeEvent.layout.width, height: event.nativeEvent.layout.height }); }; return ( <View style={styles.container} onLayout={computeSize}> <Text>Width: {dimensions.width}px</Text> <Text>Height: {dimensions.height}px</Text> </View> ); } const styles = StyleSheet.create({ container: { borderColor: '#000', borderWidth: 1, padding: 12 } }); اقتباس رابط هذا التعليق شارك على الشبكات الإجتماعية More sharing options...
0 Salah Eddin Beriani2 نشر 23 مارس 2021 أرسل تقرير مشاركة نشر 23 مارس 2021 يمكنك استخدام onLayout event handler بهذه الطريقة للحصول على حجم ال View function App() { const viewRef = useRef(null); const getSize = (layout) => { const { x, y, width, height } = layout; console.log(x); console.log(y); console.log(width); console.log(height); }; return ( <View onLayout={(event) => getSize(event.nativeEvent.layout)}> <Button title="Get Size" /> </View> ); } اقتباس رابط هذا التعليق شارك على الشبكات الإجتماعية More sharing options...
السؤال
عمر سالم2
كيف أحصل على حجم View موجود في التطبيق؟ حاولت استخدام Dimensions ولكنها لم تعمل؟
رابط هذا التعليق
شارك على الشبكات الإجتماعية
2 أجوبة على هذا السؤال
Recommended Posts
انضم إلى النقاش
يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.