Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native react native如何检测是否触摸左侧或右侧_React Native_Expo - Fatal编程技术网

React native react native如何检测是否触摸左侧或右侧

React native react native如何检测是否触摸左侧或右侧,react-native,expo,React Native,Expo,我制作了一个Instagram故事克隆版,但我有一件事要做。我怎样才能检测到是触摸了左侧还是触摸了右侧?因为如果用户触摸左侧,可以看到上一个故事;如果用户触摸右侧,可以看到下一个故事。从“React”导入React; import React from "react"; import { Dimensions, StyleSheet, View, Text, TouchableOpacity } from "react-native";

我制作了一个Instagram故事克隆版,但我有一件事要做。我怎样才能检测到是触摸了左侧还是触摸了右侧?因为如果用户触摸左侧,可以看到上一个故事;如果用户触摸右侧,可以看到下一个故事。

从“React”导入React;
import React from "react";
import {
  Dimensions,
  StyleSheet,
  View,
  Text,
  TouchableOpacity
} from "react-native";

const SCREEN_WIDTH = Dimensions.get("screen").width;

const App = () => {
  const handleLeft = () => {
    console.log("left side tapped");
  };

  const handleRight = () => {
    console.log("right side tapped");
  };

  return (
    <View style={styles.container}>
      <TouchableOpacity
        onPress={handleLeft}
        style={[styles.touchable, styles.left]}
      >
        <Text>Left side</Text>
      </TouchableOpacity>
      <TouchableOpacity
        onPress={handleRight}
        style={[styles.touchable, styles.right]}
      >
        <Text>Right side</Text>
      </TouchableOpacity>
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flexDirection: "row"
  },
  touchable: {
    flex: 1,
    width: SCREEN_WIDTH / 2
  },
  left: {
    backgroundColor: "navy"
  },
  right: {
    backgroundColor: "tomato"
  }
});

export default App;
进口{ 尺寸, 样式表, 看法 文本, 可触摸不透明度 }从“反应本族语”; const SCREEN_WIDTH=尺寸。获取(“屏幕”)。宽度; 常量应用=()=>{ 常量handleLeft=()=>{ 控制台日志(“左侧点击”); }; 常量HandlerRight=()=>{ 控制台日志(“右侧点击”); }; 返回( 左侧 右侧 ); }; const styles=StyleSheet.create({ 容器:{ flexDirection:“行” }, 可触摸:{ 弹性:1, 宽度:屏幕宽度/2 }, 左:{ 背景颜色:“海军” }, 对:{ 背景颜色:“番茄” } }); 导出默认应用程序;
非常感谢!