Câu hỏi phỏng vấn React Native
Câu hỏi

What are Touchable Interactions in React Native?

Câu trả lời

Touchable interactions in React Native refer to the various ways users can interact with elements on the screen through touch gestures. React Native provides several components specifically designed to handle these touch interactions, allowing developers to create responsive and interactive user interfaces. The primary touchable components in React Native include:

Touchable Components

  1. TouchableOpacity:

    • Functionality: Reduces the opacity of the wrapped view when pressed, providing visual feedback by dimming the element.
    • Use Case: Suitable for creating buttons or other interactive elements where a simple opacity change is sufficient feedback.
    • Example:
      import React from 'react';
      import { TouchableOpacity, Text } from 'react-native';
      
      const App = () => (
        <TouchableOpacity onPress={() => console.log('Pressed')}>
          <Text>Click Me</Text>
        </TouchableOpacity>
      );
      export default App;
    • Props: activeOpacity, onPress, style, etc.[1][2][3][13]
  2. TouchableHighlight:

    • Functionality: Darkens the background of the wrapped view when pressed.
    • Use Case: Useful when a more pronounced visual feedback is needed compared to TouchableOpacity.
    • Example:
      import React from 'react';
      import { TouchableHighlight, Text } from 'react-native';
      
      const App = () => (
        <TouchableHighlight underlayColor="#DDDDDD" onPress={() => alert('Pressed')}>
          <Text>Press Me</Text>
        </TouchableHighlight>
      );
      export default App;
    • Props: underlayColor, onPress, style, etc.[1][2][3]
  3. TouchableWithoutFeedback:

    • Functionality: Does not provide any visual feedback when pressed.
    • Use Case: Ideal for scenarios where touch handling is needed without any visual indication, such as dismissing a keyboard.
    • Example:
      import React from 'react';
      import { TouchableWithoutFeedback, View, Text } from 'react-native';
      
      const App = () => (
        <TouchableWithoutFeedback onPress={() => console.log('Pressed')}>
          <View>
            <Text>Press Me</Text>
          </View>
        </TouchableWithoutFeedback>
      );
      export default App;
    • Props: onPress, style, etc.[2][3][6]
  4. TouchableNativeFeedback:

    • Functionality: Provides native feedback (like ripple effects) on Android.
    • Use Case: Best used for Android-specific touch feedback that aligns with native Android design guidelines.
    • Example:
      import React from 'react';
      import { TouchableNativeFeedback, View, Text } from 'react-native';
      
      const App = () => (
        <TouchableNativeFeedback onPress={() => console.log('Pressed')}>...
middle

middle

Gợi ý câu hỏi phỏng vấn

expert

What is InteractionManager and how is it used?

senior

Does React Native compile JavaScript into Java for Android?

senior

What are the features of Container/Smart components?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào