الفرق بين المراجعتين ل"ReactNative/touchableopacity"

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث
(أنشأ الصفحة ب'<noinclude>{{DISPLAYTITLE: TouchableOpacity في React Native}}</noinclude> غلافٌ لجعل المكوّنات تستجيب بشكل مناسبٍ لِلّمسات....')
 
ط
 
(4 مراجعات متوسطة بواسطة مستخدمين اثنين آخرين غير معروضة)
سطر 1: سطر 1:
<noinclude>{{DISPLAYTITLE: TouchableOpacity في React Native}}</noinclude>
+
<noinclude>{{DISPLAYTITLE:المكون TouchableOpacity في React Native}}</noinclude><blockquote>'''ملاحظة''': إذا كنت تريد طريقةً أكثر شمولية للتعامل مع عناصر الإدخال باللمس اطّلع على واجهة [[ReactNative/pressable|<code>Pressable</code>]] البرمجية.</blockquote>هو غلافٌ لجعل المكوّنات تستجيب بشكل مناسبٍ لِلّمسات. عند الضغط لأسفل، تُقَلَّل عتامة (opacity) العرض المُغلَّف، ما يُعتِّمُه (أي تُخفَّض شدَّة إضاءته).
غلافٌ لجعل المكوّنات تستجيب بشكل مناسبٍ لِلّمسات. عند الضغط لأسفل، تُقَلَّل عتامة (opacity) العرض المُغلَّف، ما يُعتِّمُه (أي تُخفَّض شدَّة إضاءته).
 
  
 
يُتَحكَّم في العتامة من خلال تغليف العروض الأبناء داخل عرض ‎‎<code>Animated.View</code>‎‎، والذي يُضاف إلى التسلسل الهرمي للعرض. لاحظ أن هذا قد يؤثر على التخطيط.
 
يُتَحكَّم في العتامة من خلال تغليف العروض الأبناء داخل عرض ‎‎<code>Animated.View</code>‎‎، والذي يُضاف إلى التسلسل الهرمي للعرض. لاحظ أن هذا قد يؤثر على التخطيط.
 +
==مثال==
 +
[https://snack.expo.dev/@hsoubwiki/touchableopacity-function-component-example إليك مثال لمكون دالة (function component)]:<syntaxhighlight lang="javascript">
 +
import React, { useState } from "react";
 +
import { StyleSheet, Text, TouchableOpacity, View } from "react-native";
 +
 +
const App = () => {
 +
  const [count, setCount] = useState(0);
 +
  const onPress = () => setCount(prevCount => prevCount + 1);
  
مثال:
 
<syntaxhighlight lang="javascript">
 
renderButton: function() {
 
 
   return (
 
   return (
     <TouchableOpacity onPress={this._onPressButton}>
+
     <View style={styles.container}>
       <Image
+
       <View style={styles.countContainer}>
 +
        <Text>Count: {count}</Text>
 +
      </View>
 +
      <TouchableOpacity
 
         style={styles.button}
 
         style={styles.button}
         source={require('./myButton.png')}
+
         onPress={onPress}
       />
+
      >
     </TouchableOpacity>
+
        <Text>Press Here</Text>
 +
       </TouchableOpacity>
 +
     </View>
 
   );
 
   );
},
+
};
</syntaxhighlight>
+
 
==مثال==
+
const styles = StyleSheet.create({
<syntaxhighlight lang="javascript">
+
  container: {
import React, { Component } from 'react'
+
    flex: 1,
import {
+
    justifyContent: "center",
  StyleSheet,
+
    paddingHorizontal: 10
  TouchableOpacity,
+
  },
  Text,
+
  button: {
  View,
+
    alignItems: "center",
} from 'react-native'
+
    backgroundColor: "#DDDDDD",
 +
    padding: 10
 +
  },
 +
  countContainer: {
 +
    alignItems: "center",
 +
    padding: 10
 +
  }
 +
});
 +
 
 +
export default App;
 +
</syntaxhighlight>[https://snack.expo.dev/@hsoubwiki/touchableopacity-class-component-example إليك مثال لمكون صنف (class component)]:<syntaxhighlight lang="javascript">
 +
import React, { Component } from "react";
 +
import { StyleSheet, Text, TouchableOpacity, View } from "react-native";
  
export default class App extends Component {
+
class App extends Component {
 
   constructor(props) {
 
   constructor(props) {
     super(props)
+
     super(props);
     this.state = { count: 0 }
+
     this.state = { count: 0 };
 
   }
 
   }
  
 
   onPress = () => {
 
   onPress = () => {
 
     this.setState({
 
     this.setState({
       count: this.state.count+1
+
       count: this.state.count + 1
     })
+
     });
   }
+
   };
  
render() {
+
  render() {
  return (
+
    const { count } = this.state;
    <View style={styles.container}>
+
    return (
      <TouchableOpacity
+
      <View style={styles.container}>
        style={styles.button}
+
        <View style={styles.countContainer}>
        onPress={this.onPress}
+
          <Text>Count: {count}</Text>
      >
 
        <Text> Touch Here </Text>
 
      </TouchableOpacity>
 
      <View style={[styles.countContainer]}>
 
        <Text style={[styles.countText]}>
 
            { this.state.count !== 0 ? this.state.count: null}
 
          </Text>
 
 
         </View>
 
         </View>
 +
        <TouchableOpacity
 +
          style={styles.button}
 +
          onPress={this.onPress}
 +
        >
 +
          <Text>Press Here</Text>
 +
        </TouchableOpacity>
 
       </View>
 
       </View>
     )
+
     );
 
   }
 
   }
 
}
 
}
سطر 61: سطر 81:
 
   container: {
 
   container: {
 
     flex: 1,
 
     flex: 1,
     justifyContent: 'center',
+
     justifyContent: "center",
 
     paddingHorizontal: 10
 
     paddingHorizontal: 10
 
   },
 
   },
 
   button: {
 
   button: {
     alignItems: 'center',
+
     alignItems: "center",
     backgroundColor: '#DDDDDD',
+
     backgroundColor: "#DDDDDD",
 
     padding: 10
 
     padding: 10
 
   },
 
   },
 
   countContainer: {
 
   countContainer: {
     alignItems: 'center',
+
     alignItems: "center",
 
     padding: 10
 
     padding: 10
  },
 
  countText: {
 
    color: '#FF00FF'
 
 
   }
 
   }
})
+
});
 +
 
 +
export default App;
 
</syntaxhighlight>
 
</syntaxhighlight>
 
==الخاصيات==
 
==الخاصيات==
يرث خاصيّات المكون TouchableWithoutFeedback.
+
يرث خاصيّات المكون <code>[[ReactNative/touchablewithoutfeedback|TouchableWithoutFeedback]]</code>.
  
 
===‎‎<code>style</code>‎‎===
 
===‎‎<code>style</code>‎‎===
سطر 121: سطر 140:
 
|}
 
|}
 
===‎‎<code>hasTVPreferredFocus</code>‎‎===
 
===‎‎<code>hasTVPreferredFocus</code>‎‎===
(Apple TV فقط) التركيز المفضل على التلفاز (انظر  توثيق المكون View).
+
(Apple TV فقط) التركيز المفضل على التلفاز (انظر  توثيق المكون <code>[[ReactNative/view|View]]</code>).
 
{| class="wikitable"
 
{| class="wikitable"
 
!النوع
 
!النوع
سطر 132: سطر 151:
 
|}
 
|}
 
===‎‎<code>nextFocusDown</code>‎‎===
 
===‎‎<code>nextFocusDown</code>‎‎===
التركيز التالي في الأسفل على التلفاز (انظر  توثيق المكون View).
+
التركيز التالي في الأسفل على التلفاز (انظر  توثيق المكون <code>[[ReactNative/view|View]]</code>).
 
{| class="wikitable"
 
{| class="wikitable"
 
!النوع
 
!النوع
سطر 143: سطر 162:
 
|}
 
|}
 
===‎‎<code>nextFocusForward</code>‎‎===
 
===‎‎<code>nextFocusForward</code>‎‎===
التركيز التالي في الأمام على التلفاز (انظر  توثيق المكون View).
+
التركيز التالي في الأمام على التلفاز (انظر  توثيق المكون <code>[[ReactNative/view|View]]</code>).
 
{| class="wikitable"
 
{| class="wikitable"
 
!النوع
 
!النوع
سطر 155: سطر 174:
  
 
===‎‎<code>nextFocusLeft</code>‎‎===
 
===‎‎<code>nextFocusLeft</code>‎‎===
التركيز التالي في اليسار على التلفاز (انظر  توثيق المكون View).
+
التركيز التالي في اليسار على التلفاز (انظر  توثيق المكون <code>[[ReactNative/view|View]]</code>).
 
{| class="wikitable"
 
{| class="wikitable"
 
!النوع
 
!النوع
سطر 167: سطر 186:
  
 
===‎‎<code>nextFocusRight</code>‎‎===
 
===‎‎<code>nextFocusRight</code>‎‎===
التركيز التالي في اليمين على التلفاز (انظر  توثيق المكون View).
+
التركيز التالي في اليمين على التلفاز (انظر  توثيق المكون <code>[[ReactNative/view|View]]</code>).
 
{| class="wikitable"
 
{| class="wikitable"
 
!النوع
 
!النوع
سطر 179: سطر 198:
  
 
===‎‎<code>nextFocusUp</code>‎‎===
 
===‎‎<code>nextFocusUp</code>‎‎===
التركيز التالي في الأعلى على التلفاز (انظر  توثيق المكون View).
+
التركيز التالي في الأعلى على التلفاز (انظر  توثيق المكون <code>[[ReactNative/view|View]]</code>).
 
{| class="wikitable"
 
{| class="wikitable"
 
!النوع
 
!النوع
سطر 189: سطر 208:
 
|iOS
 
|iOS
 
|}
 
|}
==التوابع==
 
===‎‎<code>setOpacityTo()</code>‎‎===
 
<syntaxhighlight lang="javascript">
 
setOpacityTo((value: number), (duration: number));
 
</syntaxhighlight>
 
تحريك المكوّن القابل للّمس إلى قيمة عتامة جديدة.
 
 
== مصادر ==
 
== مصادر ==
 
* [https://facebook.github.io/react-native/docs/touchableopacity صفحة TouchableOpacity في توثيق React Native الرسمي.]
 
* [https://facebook.github.io/react-native/docs/touchableopacity صفحة TouchableOpacity في توثيق React Native الرسمي.]
 
[[تصنيف:ReactNative]]
 
[[تصنيف:ReactNative]]
 +
[[تصنيف:React Native Component]]

المراجعة الحالية بتاريخ 14:03، 9 أكتوبر 2021

ملاحظة: إذا كنت تريد طريقةً أكثر شمولية للتعامل مع عناصر الإدخال باللمس اطّلع على واجهة Pressable البرمجية.

هو غلافٌ لجعل المكوّنات تستجيب بشكل مناسبٍ لِلّمسات. عند الضغط لأسفل، تُقَلَّل عتامة (opacity) العرض المُغلَّف، ما يُعتِّمُه (أي تُخفَّض شدَّة إضاءته).

يُتَحكَّم في العتامة من خلال تغليف العروض الأبناء داخل عرض ‎‎Animated.View‎‎، والذي يُضاف إلى التسلسل الهرمي للعرض. لاحظ أن هذا قد يؤثر على التخطيط.

مثال

إليك مثال لمكون دالة (function component):

import React, { useState } from "react";
import { StyleSheet, Text, TouchableOpacity, View } from "react-native";

const App = () => {
  const [count, setCount] = useState(0);
  const onPress = () => setCount(prevCount => prevCount + 1);

  return (
    <View style={styles.container}>
      <View style={styles.countContainer}>
        <Text>Count: {count}</Text>
      </View>
      <TouchableOpacity
        style={styles.button}
        onPress={onPress}
      >
        <Text>Press Here</Text>
      </TouchableOpacity>
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "center",
    paddingHorizontal: 10
  },
  button: {
    alignItems: "center",
    backgroundColor: "#DDDDDD",
    padding: 10
  },
  countContainer: {
    alignItems: "center",
    padding: 10
  }
});

export default App;

إليك مثال لمكون صنف (class component):

import React, { Component } from "react";
import { StyleSheet, Text, TouchableOpacity, View } from "react-native";

class App extends Component {
  constructor(props) {
    super(props);
    this.state = { count: 0 };
  }

  onPress = () => {
    this.setState({
      count: this.state.count + 1
    });
  };

  render() {
    const { count } = this.state;
    return (
      <View style={styles.container}>
        <View style={styles.countContainer}>
          <Text>Count: {count}</Text>
        </View>
        <TouchableOpacity
          style={styles.button}
          onPress={this.onPress}
        >
          <Text>Press Here</Text>
        </TouchableOpacity>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "center",
    paddingHorizontal: 10
  },
  button: {
    alignItems: "center",
    backgroundColor: "#DDDDDD",
    padding: 10
  },
  countContainer: {
    alignItems: "center",
    padding: 10
  }
});

export default App;

الخاصيات

يرث خاصيّات المكون TouchableWithoutFeedback.

‎‎style‎‎

النوع مطلوب
‎‎View.style‎‎ لا

‎‎activeOpacity‎‎

تُحدد ما يجب أن تكون عليه عتامة العرض المُغلَّف عندما يكون اللمس نشطًا (أي أثناء لمس المستخدم العرض). القيمة الافتراضية هي ‎‎0.2‎‎.

النوع مطلوب
قيمة منطقيّة لا

‎‎tvParallaxProperties‎‎

(Apple TV فقط) كائنٌ ذو خاصيات للتحكم في تأثيرات التَّخاطُل (parallax effects) في Apple TV.

  • ‎‎enabled‎‎: إذا كانت ذات القيمة ‎‎true‎‎، فستُفعَّل تأثيرات التخاطل. قيمتها الافتراضيّة هي ‎‎true‎‎.
  • ‎‎shiftDistanceX‎‎: قيمتها الافتراضيّة هي ‎‎2.0‎‎.
  • ‎‎shiftDistanceY‎‎: قيمتها الافتراضيّة هي ‎‎2.0‎‎.
  • ‎‎tiltAngle‎‎: قيمتها الافتراضيّة هي ‎‎0.05‎‎.
  • ‎‎magnification‎‎: قيمتها الافتراضيّة هي ‎‎1.0‎‎.
  • ‎‎pressMagnification‎‎: قيمتها الافتراضيّة هي ‎‎1.0‎‎.
  • ‎‎pressDuration‎‎: قيمتها الافتراضيّة هي ‎‎0.3‎‎.
  • ‎‎pressDelay‎‎: قيمتها الافتراضيّة هي ‎‎0.0‎‎.
النوع مطلوب المنصة
كائن لا iOS

‎‎hasTVPreferredFocus‎‎

(Apple TV فقط) التركيز المفضل على التلفاز (انظر توثيق المكون View).

النوع مطلوب المنصة
قيمة منطقية لا iOS

‎‎nextFocusDown‎‎

التركيز التالي في الأسفل على التلفاز (انظر توثيق المكون View).

النوع مطلوب المنصة
قيمة منطقية لا Android

‎‎nextFocusForward‎‎

التركيز التالي في الأمام على التلفاز (انظر توثيق المكون View).

النوع مطلوب المنصة
قيمة منطقية لا Android

‎‎nextFocusLeft‎‎

التركيز التالي في اليسار على التلفاز (انظر توثيق المكون View).

النوع مطلوب المنصة
قيمة منطقية لا Android

‎‎nextFocusRight‎‎

التركيز التالي في اليمين على التلفاز (انظر توثيق المكون View).

النوع مطلوب المنصة
قيمة منطقية لا Android

‎‎nextFocusUp‎‎

التركيز التالي في الأعلى على التلفاز (انظر توثيق المكون View).

النوع مطلوب المنصة
قيمة منطقية لا iOS

مصادر