Firestore从响应本机保存可拖动图像

时间:2020-11-04 19:43:19

标签: react-native google-cloud-firestore

我正在开发一个可以添加多个图像的应用程序,可以在整个屏幕上拖动这些图像。这可以工作到一定程度。 但是我想做的是将图像,位置(x,y)保存到firestore。我还找不到能做到这一点的示例代码。

有人知道吗?

2 个答案:

答案 0 :(得分:0)

设法找到一个code snippet用于拖放html对象。根据此discussion,您可以使用element.getBoundingClientRect()方法并记录形状的位置。应该看起来像这样:

var rect = element.getBoundingClientRect();
console.log(rect.top, rect.right, rect.bottom, rect.left);

从那里开始,返回职位。您可以在adding data to a collection in Firestore上阅读此文档。

答案 1 :(得分:0)

使用panresponder时,我设法找到了解决方案。我得到x和y值,并将它们添加到firestore中。

这是我使用的代码的一部分:

+-----------------------------------+--------+-------------------+
| ``@njit`` kwargs                  |  SVML  | Execution time    |
+===================================+========+===================+
| ``None``                          | No     | 5.95s             |
+-----------------------------------+--------+-------------------+
| ``None``                          | Yes    | 2.26s             |
+-----------------------------------+--------+-------------------+
| ``fastmath=True``                 | No     | 5.97s             |
+-----------------------------------+--------+-------------------+
| ``fastmath=True``                 | Yes    | 1.8s              |
+-----------------------------------+--------+-------------------+
| ``parallel=True``                 | No     | 1.36s             |
+-----------------------------------+--------+-------------------+
| ``parallel=True``                 | Yes    | 0.624s            |
+-----------------------------------+--------+-------------------+
| ``parallel=True, fastmath=True``  | No     | 1.32s             |
+-----------------------------------+--------+-------------------+
| ``parallel=True, fastmath=True``  | Yes    | 0.576s            |
+-----------------------------------+--------+-------------------+

stageRef是Firestore的基础。 xval和yval是来自另一个文件的值。