Open4

nest: React Native Webでpreboot UIを作れないか検討 → ダメ

okuokuokuoku

Hyperscript

AIは適当なhyperscriptライブラリを採用するか、簡単なWrapperを書くことを提案してきた。まぁJSX直書きだとトランスパイラ要るもんね。。

import React from "react";
import ReactDOM from "react-dom";

// シンプルな h() を自作
function h(tagOrComponent, props, children = []) {
  // children が配列かどうか判定し、スプレッド構文で渡す
  if (Array.isArray(children)) {
    return React.createElement(tagOrComponent, props, ...children);
  }
  // 単一要素の場合はそのまま渡す
  return React.createElement(tagOrComponent, props, children);
}

const App = () =>
  h(
    "div",
    { style: { padding: "20px", backgroundColor: "#faf" } },
    [
      h("h1", null, "自作 h() の Hyperscript"),
      h(
        "p",
        null,
        "これは外部依存なしで自前の h() を使って React.createElement を簡略化した例です。"
      )
    ]
  );

ReactDOM.render(h(App), document.getElementById("root"));
okuokuokuoku

Import URLの準備 → ダメ

react-native-webpreact があれば充分なのかな。

react-native-web のexportは、

export {
    Kt as AccessibilityInfo, Ns as ActivityIndicator, Gt as Alert,
    Oa as Animated, Ka as AppRegistry, Qa as AppState, Va as Appearance,
    ns as BackHandler, tl as Button, il as CheckBox, rs as Clipboard,
    vi as DeviceEventEmitter, dr as Dimensions, ba as Easing, fi as FlatList,
    is as I18nManager, Eo as Image, ll as ImageBackground,
    Ir as InteractionManager, os as Keyboard, cl as KeyboardAvoidingView,
    us as LayoutAnimation, hs as Linking, Uc as LogBox, Ol as Modal,
    _i as NativeEventEmitter, zt as NativeModules, ys as PanResponder,
    Ml as Picker, mo as PixelRatio, Yt as Platform, Tu as Pressable,
    Nu as ProgressBar, or as RefreshControl, ku as SafeAreaView,
    Er as ScrollView, ko as SectionList, Es as Share, Du as StatusBar,
    dt as StyleSheet, ju as Switch, Mo as Text, Xu as TextInput,
    xc as Touchable, Dc as TouchableHighlight, Vc as TouchableNativeFeedback,
    el as TouchableOpacity, zc as TouchableWithoutFeedback, Bt as UIManager,
    ws as Vibration, tr as View, ci as VirtualizedList, Wc as YellowBox,
    Nt as findNodeHandle, U as processColor, Lt as render,
    Pt as unmountComponentAtNode, It as unstable_createElement,
    jc as useColorScheme, Tt as useLocaleContext, Kc as useWindowDimensions
};
export default null;

確かに react-native のコンポーネント群は概ね揃っているように見える。PreactはHyperscript風のwrapperである h をデフォルトで含んでいる。

... が、jsDelivrのESM変換が上手くいってなくてロードに失敗してしまう。

e.default が実際のcreatePrefixerになっているが、 react-native-web 側は e で参照しているので正常にロードできない。これはJSPMでも同じ問題になるので、たぶん react-native-web があんまり熱心にESMの方をメンテナンスしてないんだろう。。

原因は https://github.com/necolas/react-native-web/issues/2404 のようだ。createPrefixerの方をESMに移植する方が簡単かな。。

okuokuokuoku

あきらめ

一旦ESMサポートが比較的充実しているAtlasKitに移行しようかな。。そっちなら多分大丈夫でしょう。。

https://atlassian.design/

AtlasKitはデザインシステムでしかないので、クリップボードが無い。まぁクリップボードくらい自前で実装しろって事だな。。数行だし。。