小编Lui*_*izo的帖子

使用AsyncStorage如何以及在何处保存整个redux存储

我想知道我是否必须做这样的事情来在我的react-native应用程序中使用AsyncStorage保存我的应用程序的整个商店,并在应用程序启动时检查它是否存在.

var store;

_loadInitialState = async () => {
  try {
    var value = await AsyncStorage.getItem(STORAGE_KEY);
    if (value !== null){
      store = value;
      console.log('Recovered selection from disk: ' + value);
    } else {
      store = configureStore({});
      console.log('Initialized with no selection on disk.');
    }
  } catch (error) {
    console.log('AsyncStorage error: ' + error.message);
  }
};



export default class App extends Component {

  componentWillMount(){
    this._loadInitialState().done()
  }

  render(){
    return(
      <Provider store={store}>
        <AppContainer/>
      </Provider>
    )
  }
}
Run Code Online (Sandbox Code Playgroud)

这不行,但我希望你明白这个想法.

store react-native redux react-redux asyncstorage

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

如何使 View 元素的所有 Text 子元素具有相同的样式?

我想要一个类似于 CSS 的东西,你可以为 div 提供“颜色”样式,并且其中的任何文本都会有它。

我在一个视图组件中有多个文本组件,我希望它们都具有相同的文本颜色。

如果我将“颜色”样式传递给视图,它会发出警告。

当他们的父母可以拥有所有孩子的风格时,我想避免将相同的风格传递给所有这些孩子。

我想从这里开始:

<View>
  <Text style={styles.Warning}>
  </Text>
  <Text style={styles.Warning}>
  </Text>
  <Text style={styles.Warning}>
  </Text>
  <Text style={styles.Warning}>
  </Text>
  <Text style={styles.Warning}>
  </Text>
</View>
Run Code Online (Sandbox Code Playgroud)

对此:

<View style={styles.Warning}>
  <Text>
  </Text>
  <Text>
  </Text>
  <Text>
  </Text>
  <Text>
  </Text>
  <Text>
  </Text>
</View>
Run Code Online (Sandbox Code Playgroud)

样式为:

const styles = StyleSheet.create({
  Warning:{
    color:'#a94442'
  }
});
Run Code Online (Sandbox Code Playgroud)

(如果我不用安装任何东西就更好了)谢谢。

css text styles view react-native

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

如何防止React Native中的多个警报?

有没有办法在发送另一个之前判断屏幕上是否已经有Alert.alert()?

我有这个功能:

CheckInternet(){
  if(this.props.json.undefined){
    Alert.alert("Check your internet connection");
  }
}

ComponentDidUpdate(){
  this.CheckInternet();
}
Run Code Online (Sandbox Code Playgroud)

问题是我在该函数内部还有其他事情,我只是写了相关的代码,所以我不能把这个CheckInternet函数带到外面ComponentDidUpdate.

问题是组件在获取后会更新两次json,因此会发送两次警报.我想通过一个条件来防止同时发出两个警报,这个条件会让我知道屏幕上是否有警报.我似乎没有在Alert文档中找到类似的东西.有任何想法吗?

javascript lifecycle alerts react-native

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

如何使map函数返回单个值而不是数组?

下面这个函数的最初想法是它应该只在ID匹配时返回卡(一个对象),但是它没有返回任何东西(它返回undefined):

showDetails(cards, id){
  cards.map(function(card, index){
    if(card.id==id){
      console.log(card);
      return card;
    }
  })
}
Run Code Online (Sandbox Code Playgroud)

然后我意识到我的返回范围错误,我需要返回循环返回的内容,所以我想出了这个:

showDetails(cards, id){
  return (cards.map(function(card, index){
    if(card.id==id){
      return card;
    }
  }))
}
Run Code Online (Sandbox Code Playgroud)

上面代码的结果是:[undefined,Object]

我只是希望这个函数showDetails返回对象,而不是数组.

谢谢!

javascript dictionary function object react-native

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

如何在一定时间后自动关闭警报React Native

我想在几秒钟后自动关闭警报,而无需用户自己做。

如果可能的话,我想使用Alert(而不是AlertIOS)来做到这一点,但是如果只有AlertIOS有,那么我想我别无选择。

非常感谢你!

javascript alert react-native

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

PushNotificationIOS 是否适用于模拟器?

我正在尝试使用react-native-push-notifications基于React Native 附带的PushNotificationsIOS 的react-native 应用程序显示通知。问题是什么都没有发生,没有错误,没有通知,什么也没有。

我不确定是否在编写通知时出错,或者它在模拟器上不起作用。

谢谢!

notifications simulator push-notification react-native

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