React Native系列之Native Modules

本文介绍了如何在React Native中创建和使用Native Modules,特别是针对Toast Module的实现。通过继承ReactContextBaseJavaModule,重写getName()方法,并使用@ReactMethod注解供JavaScript调用。在MainReactPackage中注册模块,然后在JavaScript端调用。文章提供了详细的步骤和截图,以帮助开发者理解如何扩展React Native的功能。
摘要由CSDN通过智能技术生成

先来看下官网对于Native Modules的描述:

Sometimes an app needs access to a platform API that React Native doesn’t have a corresponding module for yet. Maybe you want to reuse some existing Java code without having to reimplement it in JavaScript, or write some high performance, multi-threaded code such as for image processing, a database, or any number of advanced extensions.
We designed React Native such that it is possible for you to write real native code and have access to the full power of the platform. This is a more advanced feature and we don’t expect it to be part of the usual development process, however it is essential that it exists. If React Native doesn’t support a native feature that you need, you should be able to build it yourself.

上面大概的意思是说,我们有时后需要用的API,RN并没有提供。而且我们可能会想用一些现成的java代码,或者写一些高质量、多线程的代码等等。
官网上提供了4种:

  1. Toast Module
  2. Callbacks
  3. Threading
  4. Send
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值