小编Kar*_*key的帖子

React Native Maps - takeSnapshot 不捕获标记

反应本机:https://github.com/expo/react-native/archive/sdk-42.0.0.tar.gz 反应:16.13.1 反应本机地图:0.28.0

我想将标记作为快照的一部分。当我们使用takeSnapshot方法时,所有标记都将被忽略。

const snapshot = this.viewRefTest.takeSnapshot({
  format: 'png', // image formats: 'png', 'jpg' (default: 'png')
  quality: 0.5, // image quality: 0..1 (only relevant for jpg, default: 1)
  result: 'file', // result types: 'file', 'base64' (default: 'file')
});

<MapView
  ref={(viewRefTest) => {
    this.viewRefTest = viewRefTest;
  }}
  showsUserLocation={true}
  followUserLocation={true}>
  <MapView.Marker coordinate={item.location}>
    <Image
      style={{ width: 30, height: 30 }}
      source={require('../../assets/images/trophy.png')}
    />
    <Callout style={{ width: 250, flexDirection: 'row', alignItems: 'center' }}>
      <Text>$23</Text>
      <View>
        <Text style={{ fontSize: 12 }}>Custom Text!</Text> …
Run Code Online (Sandbox Code Playgroud)

maps react-native react-native-maps

7
推荐指数
1
解决办法
1859
查看次数

解除状态,以便我可以使用 onPress 修改它

我试图弄清楚提升状态是如何工作的。目前,我正在尝试在不同的组件中使用 onPress 来更改状态。在我下面提供的小吃演示中,ListHome由于MapHome某种原因没有做出回应,但您仍然会看到我正在努力完成的任务。

我希望地图和列表“按钮”能够完成“单击此操作”的功能。

演示- 当前实现没有错误,只是除了可触摸不透明度的闪烁之外没有任何响应。(另请记住,由于某种原因,零食没有响应。我的本地设备工作正常)

编辑:所以要清楚,我希望能够whichComponentToShow从另一个组件访问和更改状态。即ListHome组件。

export default class Home extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      visible: true,
      whichComponentToShow: 'Screen1',
    };
  }

  goToMap = () => {
    this.setState({ whichComponentToShow: 'Screen2' });
  };

  render(){
    if(this.state.whichComponentToShow === 'Screen1'){
      return(
       <View style={{backgroundColor: '#d1cfcf' ,flex: 1}}>
        
        <ListHome
          renderMap = {this.goToMap.bind(this)}
        />
  }
}
Run Code Online (Sandbox Code Playgroud)
export default class ListHome extends React.Component {
  
goToMap = () => {
  this.props.renderMap();
}

<TouchableOpacity onPress={() => this.goToMap.bind(this)}> …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-native react-state

7
推荐指数
1
解决办法
234
查看次数

带有地图功能的异步等待,promise.all 不起作用

我正在使用 Expo 和 React-Native 构建一个应用程序。

我正在尝试使用 async wait 和 Promise.all 的地图函数从 firebase 加载照片,但我得到的只是一系列未解决的承诺。

renderImages = async () => {
  const images = [];

  if (this.state.images.length > 0) {
    images = this.state.images.map(async (item, index) => {
      const ref = firebase.storage().ref(item);

      var image = await ref.getDownloadURL();

      return (
        <View>
          <Image source={{ uri: image }} />
        </View>
      );
    });

    const imageArray = await Promise.all(images);

    return imageArray || [];
  }

  return (
    <View>
      <Text>STATE.IMAGES.LENGTH is 0</Text>
    </View>
  );
};
Run Code Online (Sandbox Code Playgroud)

我得到的只是

Promise {
  "_40": 0, …
Run Code Online (Sandbox Code Playgroud)

promise react-native expo

5
推荐指数
1
解决办法
870
查看次数

世博文档选择器未显示上传文件

我是反应原生的新手。我正在学习它,但我遇到了一个问题expo document picker。我使用文档选择器,但它不显示任何内容,或者有时会给出承诺拒绝错误。今天我被困在这个问题上很久了。

上传.js

import React, { useState } from "react";
import {
  StyleSheet,
  Text,
  View,
  TextInput,
  Button,
  TouchableOpacity,
} from "react-native";
import * as DocumentPicker from "expo";

const UploadFile = () => {
  pickDocument = async () => {
    let result = await DocumentPicker.getDocumentAsync({});
    console.log(result.uri);
    console.log(result);
  };

  return (
    <View style={styles.background}>
      <Text style={styles.file}>Upload CSV File</Text>
      <View style={styles.button}>
        <TouchableOpacity>
          <Button
            title="upload your file"
            color="black"
            onPress={pickDocument}
          />
        </TouchableOpacity>
      </View>
    </View>
  );
};

const styles = StyleSheet.create({
  background: {
    backgroundColor: …
Run Code Online (Sandbox Code Playgroud)

javascript react-native expo

3
推荐指数
1
解决办法
8042
查看次数

世博会后台权限异步不起作用

我正在开发一个应用程序,有时需要跟踪我的用户,因为他们在应用程序之外。我已经浏览了博览会文档,看来我应该使用前台和后台权限异步函数,但我的博览会应用程序无法识别这两个版本。有人遇到过这种情况么?我该如何解决?下面是我的一些代码:

import * as  Permissions from 'expo-permissions'; 
import * as Request from 'expo-permissions';
import * as Location from 'expo-location';
import Constants from 'expo-constants'


useEffect(() => {
    (async () => {
      if (Platform.OS === 'android' && !Constants.isDevice) {
        setErrorMsg(
          'Oops, this will not work on Snack in an Android emulator. Try it on your device!'
        );
        return;
      }
      let { status } = await Location.requestForegroundPermissionsAsync();
      if (status !== 'granted') {
        setErrorMsg('Permission to access location was denied');
        return;
      }
      let location = …
Run Code Online (Sandbox Code Playgroud)

javascript permissions background react-native expo

2
推荐指数
1
解决办法
6754
查看次数

Axios 发布表单数据在 React Native 中无法正常工作

我需要在反应本机中发送图像和一些详细信息作为表单数据

为此,我使用axiospost 方法。

这是我的代码:

const formData = new FormData();

formData.append('taskId', taskId);
formData.append('taskName', taskName);
formData.append('projectId', projectId);
formData.append('projectName', projectName);
formData.append('media', media);

const res = await Axios.post(`${URL}`, formData, {
  headers: {
    Authorization: `Bearer ${token}`,
    'Content-Type': 'multipart/form-data',
  },
});
Run Code Online (Sandbox Code Playgroud)

我的服务器获取的媒体文件为空..任何人都可以知道我在这里做错了什么!?

这是我的请求标头: 我的请求标头

PS:我已经在邮递员上进行了测试,其工作正常

javascript multipartform-data react-native axios

1
推荐指数
1
解决办法
2392
查看次数

推送到数组会删除旧数据(React Native)

我正在尝试将文本输入推入数组中。当我修改输入文本并推送它时,数组会在推送之前被擦除(不会在 console.log 中显示我之前的推送)。我缺少什么?

const [text, onChangeText] = React.useState('Useless Text');

let chatHistory = [];

function logHistory(text) {
  chatHistory.push(text);
  console.log(chatHistory);
}

return (
  <View style={styles.container}>
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <TextInput
        style={styles.input}
        onChangeText={onChangeText}
        value={text}
      />
      <Button title={'Ask the computer...'} onPress={() => logHistory(text)} />
    </View>
  </View>
);
Run Code Online (Sandbox Code Playgroud)

javascript arrays react-native

1
推荐指数
1
解决办法
972
查看次数