小编Yas*_*sir的帖子

从Firebase渲染FlatList中的数据

我正在使用React Native 0.49。我有从firebase,用户列表中获取的数据users/,此列表中的每个项目都已设置为该firebase.database().ref('users/' + userId).set(userInfo)userId是uidcurrentUser的。

现在,我正在取回(在操作中-redux):

export function getPeople(){
    return (dispatch) => {
        dispatch(getPeopleRequest());
        getData().then(result => {
            dispatch(getPeopleSuccess(result.val()))
        })
        .catch(error => {
            dispatch(getPeopleFailure(error))
        }); 
    }
}

const getData = () => {
    const userRef = firebase.database().ref('users/').limitToFirst(20);
    return userRef.once('value');     
}
Run Code Online (Sandbox Code Playgroud)

在组件中,我试图在FlatList中呈现数据,但是它没有呈现任何内容,我不知道自己在做什么错:

componentDidMount(){
   this.props.getPeople();
}
_renderItem = ({ item }) => (

    <View style={{flex: 1}}>
        <Text>{item}</Text>
    </View>
);

render(){
    const { inProgress, people, error } = this.props.peopleData;
    return (
        <FlatList
            data={people}
            renderItem={this._renderItem} 
        />
    );
}
Run Code Online (Sandbox Code Playgroud)

当控制台日志时, …

firebase react-native firebase-realtime-database redux

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

将对象键及其值推入数组

我有一个这样的对象:

{
 "id": 23,
 "name": "Jacob",
 "link": {
     "rel": "self",
     "link": "www.abc.com"
 },
 "company":{
       "data":{
           "id": 1,
           "ref": 324
       }
 }
Run Code Online (Sandbox Code Playgroud)

我想将每个键及其值存储到javascript或打字稿中的数组中,例如[[[“ id”:23],[“ name”:“ Jacob”],[“ link”:{......, ......}]] 等等

我这样做是为了可以为每个ID附加一个ID,最好的猜测是我将遍历数组并为每个ID附加一个ID / a标志..我也不知道该怎么做....如何解决这个问题 ?谢谢

javascript typescript

4
推荐指数
2
解决办法
3万
查看次数

从 latitudeDelta 和 longitudeDelta 获取以米/公里为单位的半径

我根据 2 点之间的设定距离从后端(laravel)请求数据,latitude例如longitude。纬度 = 78.3232 且经度 = 65.3234 且距离 = 30 英里/公里,获取 30 英里内的行。

我遇到的问题是distance.

我正在使用react-native-maps,放大/缩小是基于latitudeDeltalongitudeDelta的,并且当用户放大/缩小以发送到后端并根据点和获取数据时,我不知道如何计算它们的半径/距离半径/距离

目前我在客户端有这个功能。确定当用户更改区域时何时获取新数据。但它有一个硬编码的问题distance(5.0 KM)

const _onRegionChangeComplete = (onCompletedregion: Region) => {
    if (initialRegion) {
      const KMDistance = helper.distance(         
        initialRegion?.latitude,
        initialRegion?.longitude,
        onCompletedregion.latitude,
        onCompletedregion.longitude,
        "K"
      );

      if (KMDistance > 5.0) {
        props.getNearByReports({   // request backend if distance difference more than 5 kilometers
          latitude: onCompletedregion.latitude,
          longitude: onCompletedregion.longitude
        });
      }
    }
  };
Run Code Online (Sandbox Code Playgroud)

helper.distance // 获取初始点与用户更改区域后的距离差

function …
Run Code Online (Sandbox Code Playgroud)

mysql latitude-longitude laravel react-native react-native-maps

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

Firebase:使用管理员SDK存储图像

我正在尝试将图像存储到Firebase存储中,我正在使用node.js。

import * as admin from 'firebase-admin';

admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: 'https://xxx-app.firebaseio.com',
    storageBucket: 'xxxx-app.appspot.com'
});


function storeHeadShots(){

    const bucket = admin.storage().bucket();

    bucket.upload('./headshots/Acker.W.png', function(err, file){
        if (!err){
            console.log('file uploaded')
        } else {
            console.log('error uploading image: ', err)
        }
    });

}
storeHeadShots();
Run Code Online (Sandbox Code Playgroud)

现在,上面的方法可以正常工作,但是我在存储中有一个文件夹,users/并且在此文件夹中我正在存储图像。如何访问该文件夹

firebase firebase-storage firebase-admin

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

React Native:动画在android上无法正常工作

我一直试图修复过去2天的问题,它在iOS上运行正常

constructor(){
  super();

  this.animation = new Animated.Value(0)

  this.state = {
    expanded: false,
  };
}
toggle(){
  let initialValue = this.state.expanded? 1 : 0 ,
     finalValue = this.state.expanded? 0 : 1

  this.setState({
     expanded: !this.state.expanded,
  });

  this.animation.setValue(initialValue)
  Animated.timing(
    this.animation,
    {
      toValue: finalValue,
    }
  ).start();
}

render(){
  return(
    <Animated.View style={{{flex: 1, marginTop: 28, paddingLeft: 25, transform: [{ scale: this.animation }, {perspective: 1000 }]}}}>
     ....
    </Animated.View>

  );
}
Run Code Online (Sandbox Code Playgroud)

这个组件是子组件,在父组件中使用如下:<FeedBack ref={ref => this.feedback = ref}/>没有任何条件要检查显示与否(因为构造函数中的动画比例设置为零,所以不需要)

toggle()当按下按钮时,从父进程调用该方法.

现在this works fine on iOS,当组件加载时,在按下按钮(然后缩放)之前视图不存在.但是 …

react-native react-animated

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