【问题标题】:react native - How to pass JSX to swift?react native - 如何将 JSX 传递给 swift?
【发布时间】:2019-09-07 05:20:08
【问题描述】:

我使用了 react-native-directed-view,但是 react-native-directed-view 变得无人维护。

我成功使用UIScrollView 反应原生并将变量传递给原生代码。

下面是我的代码的一部分。我使用requireNativeComponent 桥接。

import {
  ...
  requireNativeComponent
} from 'react-native'
const CounterView = requireNativeComponent("CounterView")
...
render() {
  return (
    <View style={styles.container}>
      <CounterView />
    </View>
  )
}

但是!!!

我不能快速使用porps.children(HOC)。 我可以将字符串和整数传递给 swift,因为 obj-c 具有字符串和整数类型。

@objc var count: NSSumber = 0

但是obj-c中没有jsx类型

如何快速创建 HOC? react-native-directed-view 使用了带有 Objective-c 的 HOC。 我想快速使用 HOC。

我知道在 swift 中使用 RCTRootView 可以在 swift 中使用 jsx。 我想知道如何通过 JSX 以及如何将它与RCTRootView 一起使用。

理想的代码如下。

import {View, Text, requireNativeComponent}
const UIscrollView = requireNativeComponent("UIScrollView")

// HOC with native code
const App = () => (
  <UIScrollView height={100} width={100}>
    <View>
      <Text>lol</Text>
    </View>
  <UIScrollView>
)

export default App

【问题讨论】:

    标签: swift react-native bridge


    【解决方案1】:

    您是否将此库链接到本机代码。我的意思是 react-native 链接 react-native-directed-view。

    【讨论】:

    • react-native-directed-view 有很多错误。我需要创建一个新的。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-11
    • 2018-06-13
    • 2021-03-17
    • 2021-10-26
    • 2018-10-11
    • 1970-01-01
    相关资源
    最近更新 更多