react-web 学习笔记

🌙
手机阅读
本文目录结构

react-web

react-web是淘宝前端团队开发的一个可以把react-native转换成web的工具, 大体上能实现了移动端的iOS/安卓/移动web这三端的代码共用. 当然细节上是充满了各种有解无解的坑.

注意:改项目基本属于凉凉的状态,请谨慎考虑使用(安邦备注与2020年3月26日)

官方资料

安装

npm install --save react-web

使用

第一步:项目中修改 webpack 配置

在 webpack 配置中,需要添加 alias 将 react-native 指向 react-web:

// webpack.config.js

module.exports = {
  resolve: {
    alias: {
      'react-native': 'react-web'
    }
  }
}

第二步:使用 React Native API 写应用

import React, {Component} from 'react';
import {AppRegistry, StyleSheet, Text, View, Platform} from 'react-native';

class App extends Component {
  render() {
    return (
      <View style={styles.box}>
        <Text style={styles.text}>Hello, world!</Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  box: {padding: 10},
  text: {fontWeight: 'bold'}
});

AppRegistry.registerComponent('App', () => App);

if (Platform.OS === 'web') {
  AppRegistry.runApplication('App', { rootTag: document.getElementById('app') });
}

兼容列表

  • ActivityIndicator
  • ART
  • Button
  • CheckBox
  • FlatList
  • Image
  • ImageBackground
  • KeyboardAvoidingView
  • ListView
  • Modal
  • Picker
  • ProgressBar
  • RefreshControl
  • SafeAreaView
  • ScrollView
  • SectionList
  • Slider
  • StatusBar
  • Switch
  • Text
  • TextInput
  • Touchable
  • TouchableHighlight
  • TouchableNativeFeedback
  • TouchableOpacity
  • TouchableWithoutFeedback
  • View
  • VirtualizedList
  • WebView
  • findNodeHandle
  • AccessibilityInfo
  • Alert
  • Animated
  • AppRegistry
  • AppState
  • AsyncStorage
  • BackHandler
  • Clipboard
  • Dimensions
  • Easing
  • Geolocation
  • I18nManager
  • InteractionManager
  • Keyboard
  • LayoutAnimation
  • Linking
  • NetInfo
  • PanResponder
  • PixelRatio
  • Platform
  • Settings
  • StyleSheet
  • UIManager
  • Vibration
  • processColor
  • NativeModules
  • ColorPropType
  • EdgeInsetsPropType
  • PointPropType
  • ViewPropTypes

AXIHE / 精选资源

浏览全部教程

面试题

学习网站

前端培训
自己甄别

前端书籍

关于朱安邦

我叫 朱安邦,阿西河的站长,在杭州。

以前是一名平面设计师,后来开始接接触前端开发,主要研究前端技术中的JS方向。

业余时间我喜欢分享和交流自己的技术,欢迎大家关注我的 Bilibili

关注我: Github / 知乎

于2021年离开前端领域,目前重心放在研究区块链上面了

我叫朱安邦,阿西河的站长

目前在杭州从事区块链周边的开发工作,机械专业,以前从事平面设计工作。

2014年底脱产在老家自学6个月的前端技术,自学期间几乎从未出过家门,最终找到了满意的前端工作。更多>

于2021年离开前端领域,目前从事区块链方面工作了