SlideShare uma empresa Scribd logo
1 de 18
Baixar para ler offline
REACT
NATIVE
BRIDGE
FOR IOS
AND
ANDROID
www.bacancytechnology.com
React Native is combined with iOS and
Android. We can create a React Native
bridge between the Native languages like
Java, Kotlin, Objective-c, Swift, and
JavaScript code. Here bridge means the
communication between the native
platform and React Native.
Native Bridge Android
Native Bridge iOS
Table of Contents
1. Native Modules 
2. Native Bridge component
In this blog post, I will get you through both
Android as well as iOS.
Define Native Modules
Native modules are distributed as npm
packages, except that on top of the usual
Javascript, they will include some native
code per platform. To understand more
about npm packages, please go through this
useful Guide.
Native Module Steps:
Let’s understand the native modules with
examples.
Create the Exit App
We will create an ExitApp demo using react-
native CLI. In this example, button press to
exit the app using the native language.
Hopefully, your project runs successfully.
Native Bridge component
This tool comes handy for React Native
Developer to bridge the native component
1. Native Bridge Android
Create a new java class, ExitModule, and
ExitModulePackage.
ExitModule.java
⦿android/app/src/main/java/com/exitapp/
ExitModule.java
So it is a class that extends
ReactContextBaseJavaModule.
ReactContextBaseJavaModule implements a
method getName that returns a string.
getName() in string name, which we will
refer to the native module in our Javascript
code.
@ReactMethod java method should be
annotated to expose a method to JavaScript.
Multiple @ReactMethod methods can be
created in this class.
ExitPackage.java
⦿android/app/src/main/java/com/exitapp/
ExitPackage.java
So it is a class that extends ReactPackage.
Registering new JS modules that can be
accessed from native modules or from other
parts.
The native code requires JS modules from
the package that doesn’t automatically be
included as a part of the JS bundle, so there
should be a corresponding piece of code on
the JS side that will require the
implementation of that JS module so that it
gets bundled.
MainApplication.java
⦿android/app/src/main/java/com/exitapp/
MainApplication.java
ExitPackage add in MainApplication.java
Create new file ExitModule in Xcode
File/New/File/Cocoa Touch Class
2. Native Bridge iOS
ExitModule.h
⦿ios/ExitApp/ExitModule.h
RCTBridgeModule use in native land to talk
with React Native
ExitModule.m
⦿ios/ExitApp/ExitModule.m
React Native will not expose any methods
of ExitApp to JavaScript unless explicitly
told to. This is done using the
RCT_EXPORT_METHOD() macro:
Your class must also include the
RCT_EXPORT_MODULE() macro. RCT is
the short name for React and includes it in
your Objective-C code.
RCT_EXPORT_METHOD supports this
standard JSON object types:
NSString (string)
NSInteger, float, double, CGFloat,
NSNumber(number)
BOOL, NSNumber(boolean)
NSArray (array)
NSDictionary (object)
RCTResponseSenderBlock (function)
Finally, Android and iOS side native code
are completed. So ExitApp calls in react-
native in a javascript file.
NativeModule.js
App.js
OutPut:
Now run the app
To access the code of this blog post can be
accessed here .
In this blog, we have created UI
components using React Native JavaScript
code. If you are looking for the React Native
experts to create a bridge between
JavaScript code and native languages to
create native modules, then get in touch
with us today. Our React Native developers
are well-versed with building intuitive,
visually stunning, robust, scalable,
engaging, and user-friendly cross-platform
mobile applications.
We are a globally renowned React Native
Development company; we let you
outsource React Native developers from us
to gain a competitive advantage fulfilling
your varied business objectives.
Conclusion
Thank You

Mais conteúdo relacionado

Mais procurados

Cara Tepat Menjadi iOS Developer Expert - Gilang Ramadhan
Cara Tepat Menjadi iOS Developer Expert - Gilang RamadhanCara Tepat Menjadi iOS Developer Expert - Gilang Ramadhan
Cara Tepat Menjadi iOS Developer Expert - Gilang Ramadhan
DicodingEvent
 
Scala on-android
Scala on-androidScala on-android
Scala on-android
Max Lv
 
Presentation # 4
Presentation # 4Presentation # 4
Presentation # 4
s1150149
 

Mais procurados (20)

Dependency injection using dagger2
Dependency injection using dagger2Dependency injection using dagger2
Dependency injection using dagger2
 
Gwt and JSR 269's Pluggable Annotation Processing API
Gwt and JSR 269's Pluggable Annotation Processing APIGwt and JSR 269's Pluggable Annotation Processing API
Gwt and JSR 269's Pluggable Annotation Processing API
 
Jython Presentation
Jython PresentationJython Presentation
Jython Presentation
 
Cara Tepat Menjadi iOS Developer Expert - Gilang Ramadhan
Cara Tepat Menjadi iOS Developer Expert - Gilang RamadhanCara Tepat Menjadi iOS Developer Expert - Gilang Ramadhan
Cara Tepat Menjadi iOS Developer Expert - Gilang Ramadhan
 
Kotlin multiplataforma
Kotlin multiplataformaKotlin multiplataforma
Kotlin multiplataforma
 
Web development tool
Web development toolWeb development tool
Web development tool
 
Study Jam: Android for Beginners, Summary
Study Jam: Android for Beginners, SummaryStudy Jam: Android for Beginners, Summary
Study Jam: Android for Beginners, Summary
 
Angular 2 Seminar_(December 7/12/2015)
Angular 2 Seminar_(December 7/12/2015)Angular 2 Seminar_(December 7/12/2015)
Angular 2 Seminar_(December 7/12/2015)
 
Java articles
Java articlesJava articles
Java articles
 
Android the Agile way
Android the Agile wayAndroid the Agile way
Android the Agile way
 
Scala on-android
Scala on-androidScala on-android
Scala on-android
 
Presentation # 4
Presentation # 4Presentation # 4
Presentation # 4
 
A journey with Target Platforms
A journey with Target PlatformsA journey with Target Platforms
A journey with Target Platforms
 
Gradle and Android Studio : Best of Friends
Gradle and Android Studio : Best of FriendsGradle and Android Studio : Best of Friends
Gradle and Android Studio : Best of Friends
 
Code Obfuscation for Android & WP7
Code Obfuscation for Android & WP7Code Obfuscation for Android & WP7
Code Obfuscation for Android & WP7
 
Using Dagger in a Clean Architecture project
Using Dagger in a Clean Architecture projectUsing Dagger in a Clean Architecture project
Using Dagger in a Clean Architecture project
 
How to build Sdk? Best practices
How to build Sdk? Best practicesHow to build Sdk? Best practices
How to build Sdk? Best practices
 
Telerik Kendo UI vs. AngularJS
Telerik Kendo UI vs. AngularJSTelerik Kendo UI vs. AngularJS
Telerik Kendo UI vs. AngularJS
 
From zero to hero with React Native!
From zero to hero with React Native!From zero to hero with React Native!
From zero to hero with React Native!
 
Kotlin
KotlinKotlin
Kotlin
 

Semelhante a React native bridge for iOS and android

Chapter 2.1
Chapter 2.1Chapter 2.1
Chapter 2.1
sotlsoc
 

Semelhante a React native bridge for iOS and android (20)

Lecture 1 Introduction to React Native.pptx
Lecture 1 Introduction to React Native.pptxLecture 1 Introduction to React Native.pptx
Lecture 1 Introduction to React Native.pptx
 
React Basic and Advance || React Basic
React Basic and Advance   || React BasicReact Basic and Advance   || React Basic
React Basic and Advance || React Basic
 
Codename one
Codename oneCodename one
Codename one
 
Getting started with the NDK
Getting started with the NDKGetting started with the NDK
Getting started with the NDK
 
Hacking the Codename One Source Code - Part IV - Transcript.pdf
Hacking the Codename One Source Code - Part IV - Transcript.pdfHacking the Codename One Source Code - Part IV - Transcript.pdf
Hacking the Codename One Source Code - Part IV - Transcript.pdf
 
Nativescript with angular 2
Nativescript with angular 2Nativescript with angular 2
Nativescript with angular 2
 
React Native for multi-platform mobile applications
React Native for multi-platform mobile applicationsReact Native for multi-platform mobile applications
React Native for multi-platform mobile applications
 
Ignite your app development with Angular, NativeScript and Firebase
Ignite your app development with Angular, NativeScript and FirebaseIgnite your app development with Angular, NativeScript and Firebase
Ignite your app development with Angular, NativeScript and Firebase
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language
 
Building framework with shared code on Android and iOS using React Native. UA...
Building framework with shared code on Android and iOS using React Native. UA...Building framework with shared code on Android and iOS using React Native. UA...
Building framework with shared code on Android and iOS using React Native. UA...
 
Android
Android Android
Android
 
GITS Class #20: Building A Fast and Responsive UI in React Native
GITS Class #20: Building A Fast and Responsive UI in React NativeGITS Class #20: Building A Fast and Responsive UI in React Native
GITS Class #20: Building A Fast and Responsive UI in React Native
 
Synapseindia android apps application
Synapseindia android apps applicationSynapseindia android apps application
Synapseindia android apps application
 
Hello, Android Studio 3.2 & Android App Bundle @ I/O Extended Bangkok 2018
Hello, Android Studio 3.2 & Android App Bundle @ I/O Extended Bangkok 2018Hello, Android Studio 3.2 & Android App Bundle @ I/O Extended Bangkok 2018
Hello, Android Studio 3.2 & Android App Bundle @ I/O Extended Bangkok 2018
 
Extending Appcelerator Titanium Mobile through Native Modules
Extending Appcelerator Titanium Mobile through Native ModulesExtending Appcelerator Titanium Mobile through Native Modules
Extending Appcelerator Titanium Mobile through Native Modules
 
Mobile development in 2020
Mobile development in 2020 Mobile development in 2020
Mobile development in 2020
 
Programming
ProgrammingProgramming
Programming
 
Getting Native with NDK
Getting Native with NDKGetting Native with NDK
Getting Native with NDK
 
Chapter 2.1
Chapter 2.1Chapter 2.1
Chapter 2.1
 
[Ultracode Munich #4] Short introduction to the new Android build system incl...
[Ultracode Munich #4] Short introduction to the new Android build system incl...[Ultracode Munich #4] Short introduction to the new Android build system incl...
[Ultracode Munich #4] Short introduction to the new Android build system incl...
 

Mais de Katy Slemon

Mais de Katy Slemon (20)

React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdfReact Alternatives Frameworks- Lightweight Javascript Libraries.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
 
Data Science Use Cases in Retail & Healthcare Industries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdfData Science Use Cases in Retail & Healthcare Industries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdf
 
How Much Does It Cost To Hire Golang Developer.pdf
How Much Does It Cost To Hire Golang Developer.pdfHow Much Does It Cost To Hire Golang Developer.pdf
How Much Does It Cost To Hire Golang Developer.pdf
 
What’s New in Flutter 3.pdf
What’s New in Flutter 3.pdfWhat’s New in Flutter 3.pdf
What’s New in Flutter 3.pdf
 
Why Use Ruby On Rails.pdf
Why Use Ruby On Rails.pdfWhy Use Ruby On Rails.pdf
Why Use Ruby On Rails.pdf
 
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdfHow Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
 
How to Implement Middleware Pipeline in VueJS.pdf
How to Implement Middleware Pipeline in VueJS.pdfHow to Implement Middleware Pipeline in VueJS.pdf
How to Implement Middleware Pipeline in VueJS.pdf
 
How to Build Laravel Package Using Composer.pdf
How to Build Laravel Package Using Composer.pdfHow to Build Laravel Package Using Composer.pdf
How to Build Laravel Package Using Composer.pdf
 
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdfSure Shot Ways To Improve And Scale Your Node js Performance.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
 
How to Develop Slack Bot Using Golang.pdf
How to Develop Slack Bot Using Golang.pdfHow to Develop Slack Bot Using Golang.pdf
How to Develop Slack Bot Using Golang.pdf
 
IoT Based Battery Management System in Electric Vehicles.pdf
IoT Based Battery Management System in Electric Vehicles.pdfIoT Based Battery Management System in Electric Vehicles.pdf
IoT Based Battery Management System in Electric Vehicles.pdf
 
Understanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdfUnderstanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdf
 
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdfThe Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
 
New Features in iOS 15 and Swift 5.5.pdf
New Features in iOS 15 and Swift 5.5.pdfNew Features in iOS 15 and Swift 5.5.pdf
New Features in iOS 15 and Swift 5.5.pdf
 
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdfHow to Hire & Manage Dedicated Team For Your Next Product Development.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
 
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdfChoose the Right Battery Management System for Lithium Ion Batteries.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
 
Flutter Performance Tuning Best Practices From the Pros.pdf
Flutter Performance Tuning Best Practices From the Pros.pdfFlutter Performance Tuning Best Practices From the Pros.pdf
Flutter Performance Tuning Best Practices From the Pros.pdf
 
Angular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdfAngular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdf
 
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdfHow to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
 
Ruby On Rails Performance Tuning Guide.pdf
Ruby On Rails Performance Tuning Guide.pdfRuby On Rails Performance Tuning Guide.pdf
Ruby On Rails Performance Tuning Guide.pdf
 

Último

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Último (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

React native bridge for iOS and android

  • 2. React Native is combined with iOS and Android. We can create a React Native bridge between the Native languages like Java, Kotlin, Objective-c, Swift, and JavaScript code. Here bridge means the communication between the native platform and React Native.
  • 3. Native Bridge Android Native Bridge iOS Table of Contents 1. Native Modules  2. Native Bridge component
  • 4. In this blog post, I will get you through both Android as well as iOS. Define Native Modules Native modules are distributed as npm packages, except that on top of the usual Javascript, they will include some native code per platform. To understand more about npm packages, please go through this useful Guide. Native Module Steps: Let’s understand the native modules with examples. Create the Exit App We will create an ExitApp demo using react- native CLI. In this example, button press to exit the app using the native language.
  • 5. Hopefully, your project runs successfully. Native Bridge component This tool comes handy for React Native Developer to bridge the native component 1. Native Bridge Android Create a new java class, ExitModule, and ExitModulePackage. ExitModule.java ⦿android/app/src/main/java/com/exitapp/ ExitModule.java So it is a class that extends ReactContextBaseJavaModule.
  • 6. ReactContextBaseJavaModule implements a method getName that returns a string. getName() in string name, which we will refer to the native module in our Javascript code. @ReactMethod java method should be annotated to expose a method to JavaScript. Multiple @ReactMethod methods can be created in this class.
  • 7.
  • 8. ExitPackage.java ⦿android/app/src/main/java/com/exitapp/ ExitPackage.java So it is a class that extends ReactPackage. Registering new JS modules that can be accessed from native modules or from other parts. The native code requires JS modules from the package that doesn’t automatically be included as a part of the JS bundle, so there should be a corresponding piece of code on the JS side that will require the implementation of that JS module so that it gets bundled.
  • 9.
  • 11. Create new file ExitModule in Xcode File/New/File/Cocoa Touch Class 2. Native Bridge iOS
  • 12. ExitModule.h ⦿ios/ExitApp/ExitModule.h RCTBridgeModule use in native land to talk with React Native ExitModule.m ⦿ios/ExitApp/ExitModule.m React Native will not expose any methods of ExitApp to JavaScript unless explicitly told to. This is done using the RCT_EXPORT_METHOD() macro:
  • 13. Your class must also include the RCT_EXPORT_MODULE() macro. RCT is the short name for React and includes it in your Objective-C code. RCT_EXPORT_METHOD supports this standard JSON object types:
  • 14. NSString (string) NSInteger, float, double, CGFloat, NSNumber(number) BOOL, NSNumber(boolean) NSArray (array) NSDictionary (object) RCTResponseSenderBlock (function) Finally, Android and iOS side native code are completed. So ExitApp calls in react- native in a javascript file. NativeModule.js
  • 16. OutPut: Now run the app To access the code of this blog post can be accessed here .
  • 17. In this blog, we have created UI components using React Native JavaScript code. If you are looking for the React Native experts to create a bridge between JavaScript code and native languages to create native modules, then get in touch with us today. Our React Native developers are well-versed with building intuitive, visually stunning, robust, scalable, engaging, and user-friendly cross-platform mobile applications. We are a globally renowned React Native Development company; we let you outsource React Native developers from us to gain a competitive advantage fulfilling your varied business objectives. Conclusion