<legend id='bA6oB'><style id='bA6oB'><dir id='bA6oB'><q id='bA6oB'></q></dir></style></legend>

<small id='bA6oB'></small><noframes id='bA6oB'>

  • <i id='bA6oB'><tr id='bA6oB'><dt id='bA6oB'><q id='bA6oB'><span id='bA6oB'><b id='bA6oB'><form id='bA6oB'><ins id='bA6oB'></ins><ul id='bA6oB'></ul><sub id='bA6oB'></sub></form><legend id='bA6oB'></legend><bdo id='bA6oB'><pre id='bA6oB'><center id='bA6oB'></center></pre></bdo></b><th id='bA6oB'></th></span></q></dt></tr></i><div id='bA6oB'><tfoot id='bA6oB'></tfoot><dl id='bA6oB'><fieldset id='bA6oB'></fieldset></dl></div>
      • <bdo id='bA6oB'></bdo><ul id='bA6oB'></ul>
        <tfoot id='bA6oB'></tfoot>

        Expo + React Native:在两种视图的坐标之间画线

        Expo + React Native: Draw line between coordinates on two type of views(Expo + React Native:在两种视图的坐标之间画线)

        • <bdo id='sWBdb'></bdo><ul id='sWBdb'></ul>

            <tbody id='sWBdb'></tbody>
          <tfoot id='sWBdb'></tfoot>

          <small id='sWBdb'></small><noframes id='sWBdb'>

          <legend id='sWBdb'><style id='sWBdb'><dir id='sWBdb'><q id='sWBdb'></q></dir></style></legend>
            <i id='sWBdb'><tr id='sWBdb'><dt id='sWBdb'><q id='sWBdb'><span id='sWBdb'><b id='sWBdb'><form id='sWBdb'><ins id='sWBdb'></ins><ul id='sWBdb'></ul><sub id='sWBdb'></sub></form><legend id='sWBdb'></legend><bdo id='sWBdb'><pre id='sWBdb'><center id='sWBdb'></center></pre></bdo></b><th id='sWBdb'></th></span></q></dt></tr></i><div id='sWBdb'><tfoot id='sWBdb'></tfoot><dl id='sWBdb'><fieldset id='sWBdb'></fieldset></dl></div>
                1. 本文介绍了Expo + React Native:在两种视图的坐标之间画线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我目前正在使用这个模块:

                  我希望它是一条平滑的线,而不是上图的一系列圆圈.

                  解决方案

                  您将需要像 Canvas 这样的东西来绘制线条而不是像素(使用视图).React Native 目前没有 Canvas 实现.

                  在 expo 中最简单的方法是使用 react-native-svg 库.

                  使用它,您可以通过以下实现从手势数据中绘制一条折线:

                  import Svg, { Polyline } from 'react-native-svg';const GesturePath = ({ path, color }) =>{const { 宽度,高度 } = Dimensions.get('window');常量点 = path.map(p => `${p.x},${p.y}`).join(' ');返回 (<Svg height="100%" width="100%" viewBox={`0 0 ${width} ${height}`}><折线点={点}填充=无"中风={颜色}行程宽度=1"/></Svg>);};

                  您还可以在没有 react-native-gesture-detector 库的情况下使用内置的 React Native PanResponder.这是一个例子:

                  const GestureRecorder = ({ onPathChanged }) =>{常量 pathRef = useRef([]);常量 panResponder = useRef(PanResponder.create({onMoveShouldSetPanResponder: () =>真的,onPanResponderGrant: () =>{pathRef.current = [];},onPanResponderMove: (事件) =>{pathRef.current.push({x: event.nativeEvent.locationX,y: event.nativeEvent.locationY,});//实时更新路径(必须创建一个新数组//这样 setState 会识别更改并重新渲染 App):onPathChanged([...pathRef.current]);},onPanResponderRelease: () =>{onPathChanged(pathRef.current);}})).当前的;返回 (<查看样式={StyleSheet.absoluteFill}{...panResponder.panHandlers}/>);}

                  查看此零食以了解将所有内容捆绑在一起的有效应用程序:https://snack.expo.io/@mtkopone/draw-gesture-path

                  I am currently using this module: https://github.com/mxmzb/react-native-gesture-detector. I want to be able to draw a line from the points created. however, it only seems to output circles.

                  It has a "Create Gesture" view:

                  <View style={{ position: "relative", width: "100%", height: "100%" }}>
                      <GesturePath
                          path={gesture.map(coordinate => {
                              if (recorderOffset) {
                                  return {
                                      x: coordinate.x + recorderOffset.x,
                                      y: coordinate.y + recorderOffset.y,
                                  };
                              }
                  
                              return coordinate;
                          })}
                          color="green"
                          slopRadius={30}
                          center={false}
                      />
                  </View>
                  

                  GesturePath is defined like so:

                  const GesturePath = ({ path, color, slopRadius, center = true }: GesturePathProps) => {
                    const baseStyle: ViewStyle = {
                      position: "absolute",
                      top: center ? "50%" : 0,
                      left: center ? "50%" : 0,
                      opacity: 1,
                    };
                  
                    return (
                      <>
                        {path.map((point, index) => (
                          <Animated.View
                            style={Object.assign({}, baseStyle, {
                              width: slopRadius,
                              height: slopRadius,
                              borderRadius: slopRadius,
                              backgroundColor: color,
                              marginLeft: point.x - slopRadius,
                              marginTop: point.y - slopRadius,
                            })}
                            key={index}
                          />
                        ))}
                      </>
                    );
                  };
                  

                  When you draw on that view, it outlines the path using dots, like so:

                  I would like it to be a smooth line and not a series of circles that the above image.

                  解决方案

                  You are going to need something like a Canvas to draw lines instead of pixels (with Views). React Native does not currently come with a Canvas implementation.

                  The easiest way to do this in expo is to use the react-native-svg library.

                  Using that, you can draw a polyline from your gesture data with the following implementation:

                  import Svg, { Polyline } from 'react-native-svg';
                  
                  const GesturePath = ({ path, color }) => {
                    const { width, height } = Dimensions.get('window');
                    const points = path.map(p => `${p.x},${p.y}`).join(' ');
                    return (
                      <Svg height="100%" width="100%" viewBox={`0 0 ${width} ${height}`}>
                          <Polyline
                            points={points}
                            fill="none"
                            stroke={color}
                            strokeWidth="1"
                          />
                      </Svg>    
                    );
                  };
                  

                  You can also record gestures without the react-native-gesture-detector library by using the in-built React Native PanResponder. Here is an example:

                  const GestureRecorder = ({ onPathChanged }) => {
                    const pathRef = useRef([]);
                  
                    const panResponder = useRef(
                      PanResponder.create({
                        onMoveShouldSetPanResponder: () => true,
                        onPanResponderGrant: () => {
                          pathRef.current = [];
                        },
                        onPanResponderMove: (event) => {
                          pathRef.current.push({
                            x: event.nativeEvent.locationX,
                            y: event.nativeEvent.locationY,
                          });
                          // Update path real-time (A new array must be created
                          // so setState recognises the change and re-renders the App):
                          onPathChanged([...pathRef.current]);
                        },
                        onPanResponderRelease: () => {
                          onPathChanged(pathRef.current);
                        }
                      })
                    ).current;
                  
                    return (
                      <View
                        style={StyleSheet.absoluteFill}
                        {...panResponder.panHandlers}
                      />
                    );
                  }
                  

                  See this snack for a working App tying everything together: https://snack.expo.io/@mtkopone/draw-gesture-path

                  这篇关于Expo + React Native:在两种视图的坐标之间画线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Gradient Button to background-color blinks on hover(悬停时背景颜色的渐变按钮闪烁)
                  How to make hovering over active button not use hover effect?(如何使悬停在活动按钮上不使用悬停效果?)
                  html javascript show image hover(html javascript 显示图像悬停)
                  How to get css hover values on click?(如何在点击时获得 css 悬停值?)
                  Change background image on link hover(更改链接悬停时的背景图像)
                  Highlight multiple items on hover#39;s condition(突出显示悬停条件下的多个项目)
                    <bdo id='6oPE8'></bdo><ul id='6oPE8'></ul>
                      <tbody id='6oPE8'></tbody>
                  • <small id='6oPE8'></small><noframes id='6oPE8'>

                    <i id='6oPE8'><tr id='6oPE8'><dt id='6oPE8'><q id='6oPE8'><span id='6oPE8'><b id='6oPE8'><form id='6oPE8'><ins id='6oPE8'></ins><ul id='6oPE8'></ul><sub id='6oPE8'></sub></form><legend id='6oPE8'></legend><bdo id='6oPE8'><pre id='6oPE8'><center id='6oPE8'></center></pre></bdo></b><th id='6oPE8'></th></span></q></dt></tr></i><div id='6oPE8'><tfoot id='6oPE8'></tfoot><dl id='6oPE8'><fieldset id='6oPE8'></fieldset></dl></div>

                        1. <legend id='6oPE8'><style id='6oPE8'><dir id='6oPE8'><q id='6oPE8'></q></dir></style></legend>

                          • <tfoot id='6oPE8'></tfoot>