小编Chr*_*ris的帖子

如何在 React Native ListView 中居中显示项目?

选择时,我试图将一个项目置于水平 listView 中。我目前的策略是首先测量项目并滚动到视图中引用项目的 x 坐标。

在此处输入图片说明

目前,任何时候我按下一个项目都会ListView滚动到最后x: 538

有没有更简单的方法来实现这一点,同时保持代码无状态/功能?

const ItemScroll = (props) => {

  const createItem = (obj, rowID) => {

    const isCurrentlySelected = obj.id === props.currentSelectedID

    function scrollToItem(_scrollViewItem, _scrollView) {
      // measures the item coordinates
      _scrollViewItem.measure((fx) => {
        console.log('measured fx: ', fx)
        const itemFX = fx;
        // scrolls to coordinates
        return _scrollView.scrollTo({ x: itemFX });
      });
    }
    return (
      <TouchableHighlight
        ref={(scrollViewItem) => { _scrollViewItem = scrollViewItem; }}
        isCurrentlySelected={isCurrentlySelected}
        style={isCurrentlySelected ? styles.selectedItemContainerStyle : styles.itemContainerStyle}
        key={rowID}
        onPress={() => …
Run Code Online (Sandbox Code Playgroud)

javascript listview functional-programming react-native

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

React Native 开发人员菜单未加载

在iPhone模拟器开发者菜单将不会推出任何cmd + Dcmd + ctrl + z

  • 我检查过的东西(无序):

    • cmd + r 工作正常
    • myApp 和 myAppTests 方案设置为调试模式
    • 慢速动画已关闭
    • 硬件 > 键盘 > 连接硬件键盘已打开
    • watchman 4.7.0安装有brew install watchman(--HEAD需要libtoolize,其中brew更改为glibtoolize,因此./autogen找不到它)
    • 清除派生数据文件夹
    • 为目标创建了新方案
    • 将 XCode 升级到 8.2.1 -> 8.3.1
    • react-native start --clear-cache启动成功,react-native run-ios构建成功
  • 其他事宜

    • nw_connection_get_connected_socket_block_invoke 1262 Connection has no connected handler 无限期运行
    • react-native run-ios 产出

    命令失败:/usr/libexec/PlistBuddy -c 打印:CFBundleIdentifier build/Build/Products/Debug-iphonesimulator/zelosApp.app/Info.plist 打印:条目,“:CFBundleIdentifier”,不存在命令失败:/usr/libexec/ PlistBuddy -c 打印:CFBundleIdentifier build/Build/Products/Debug-iphonesimulator/zelosApp.app/Info.plist 打印:条目,“:CFBundleIdentifier”,不存在

  • 版本

    • react-native = "^0.43.3"
    • 守望者 = "4.7.0"
    • xcode = …

xcode ios react-native

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

将对象映射到ES6中的对象数组

如何在保留键名的同时将对象转换为对象数组?

// actual 
obj = {
  key1: null,
  key2: "Nelly",
  key3: [ "suit", "sweat" ]
} 

// expected 
arr = [
  { key2: "Nelly" },
  { key3: [ "suit", "sweat" ] }
]
Run Code Online (Sandbox Code Playgroud)

目前我的解决方案是......

 var arr = Object.keys(obj).map(key => { if (obj[key]) return { key: obj[key] } });
Run Code Online (Sandbox Code Playgroud)

返回

arr = [
  undefined,
  { key: "Nelly" },
  { key: [ "suit", "sweat" ] }
]
Run Code Online (Sandbox Code Playgroud)

javascript ecmascript-6

0
推荐指数
2
解决办法
630
查看次数