React Native中使用Markdown编辑器

本文介绍如何在React Native项目中使用Markdown编辑器。通过React Native WebView组件加载HTML页面,实现Web和React Native的通信,同时展示了封装Vditor编辑器的过程,包括准备HTML文件、创建React Native组件等步骤。
摘要由CSDN通过智能技术生成

最近在研究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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
>