الفرق بين المراجعتين ل"ReactNative/using a scrollview"

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث
(إضافة الصّفحة)
(لا فرق)

مراجعة 11:26، 25 يناير 2019


استخدام المكوّن ScrollView

ScrollView حاويةٌ تمريرٍ (scrolling container) تحوي عدّة مكوناتٍ وعروض. ليس من الضروري أن تكون العناصر متجانسة، ويمكنك التمرير عموديًا وأفقيًا (عن طريق تعيين الخاصية ‎horizontal‎).

يُنشئ هذا المثال عرضَ ScrollView عمودي بصور ونصوص مختلطة مع بعضها البعض.

import React, { Component } from 'react';
import { AppRegistry, ScrollView, Image, Text } from 'react-native';

export default class IScrolledDownAndWhatHappenedNextShockedMe extends Component {
  render() {
      return (
        <ScrollView>
          <Text style={{fontSize:96}}>Scroll me plz</Text>
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Text style={{fontSize:96}}>If you like</Text>
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Text style={{fontSize:96}}>Scrolling down</Text>
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Text style={{fontSize:96}}>What's the best</Text>
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Text style={{fontSize:96}}>Framework around?</Text>
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Image source={{uri: "https://facebook.github.io/react-native/img/favicon.png", width: 64, height: 64}} />
          <Text style={{fontSize:80}}>React Native</Text>
        </ScrollView>
    );
  }
}

// تخطّ هذا السطر إن كنت تستعمل أداة 
// Create React Native App
AppRegistry.registerComponent(
  'AwesomeProject',
  () => IScrolledDownAndWhatHappenedNextShockedMe);

يمكن ضبط عروضِ ‎ScrollView‎ للسماح بالانتقال عبر العروض بإيماءات السحب (swiping gestures) باستخدام الخاصيّة ‎pagingEnabled‎. يمكن أيضًا الحصول على إمكانيّة التمرير الأفقيّ بين العروض على Android باستخدام المكوّن ‎ViewPagerAndroid‎.

يمكن استخدامُ مكوّن ScrollView مع عنصر واحد للسماح للمستخدم بتكبير المحتوى. كل ما عليك فعله هو ضبط الحد الأقصى لسلّم التكبير بالخاصيّة ‎maximumZoomScale‎ والحد الأدنى له بالخاصيّة ‎minimumZoomScale‎ وسيتمكن مستخدم التطبيق من التكبير والتصغير عبر إيماءتي التوسعة (expand) والقرص (pinch).

المكوّن ScrollView فعّالٌ لعرض بيانات قليلة ذات حجم محدود. إذ تُصيَّر جميع العناصر والعروض المجودة داخل المكوّن ScrollView ، حتى إذا لم تكن معروضة حاليًا على الشاشة. إذا كانت لديك قائمة طويلة من العناصر أكثر مما يمكن احتواءه على الشاشة، فيجب عليك استخدام المكوّن FlatList بدلاً منه. لذا لنتعرف على طرق عرض القوائم فعاليّة وأداء أفضل.