最近在研究React Native,准备用它写一个笔记APP,但是并没有搜到很好用的编辑器插件,因此准备使用WebView和已有的Web端编辑器自己封装一个。
因本人没有苹果电脑,因此只尝试安卓版本
完整项目地址:Tuzilow/rn-xnote
React Native WebView
WebView是一个能够在原生APP上加载HTML页面的组件,不过它没有提供浏览器的地址栏、导航栏等功能。在原生APP的开发中经常会用到。
安装
npm install react-native-webview
# or yarn add react-native-webview
基本使用
引入URL
import React, {
Component } from 'react';
import {
WebView } from 'react-native';
export default function MyWeb () {
return (
<WebView
source={
{
uri: 'https://github.com/facebook/react-native'}}
/>
);
}
引入本地文件
import React, {
Component } from 'react';
import {
WebView, Platform } from 'react-native';
export default function MyWeb () {
return (
<WebView
source={
Platform.OS === 'ios'
? require('../../../assets/vditor.html')
: {
uri: 'file:///android_asset/vditor.html'}
}
/>
);
}
Web和React Native之间的通信
Web到React Native
window.ReactNativeWebView.postMessage(messag

本文介绍如何在React Native项目中使用Markdown编辑器。通过React Native WebView组件加载HTML页面,实现Web和React Native的通信,同时展示了封装Vditor编辑器的过程,包括准备HTML文件、创建React Native组件等步骤。
最低0.47元/天 解锁文章
575

被折叠的 条评论
为什么被折叠?



