본문 바로가기
JavaScript/React-Native

React-Native NativeModules 네이티브 모듈 만들기

by 봉이로그 2023. 4. 26.

https://reactnative.dev/docs/native-modules-android

 

Android Native Modules · React Native

Welcome to Native Modules for Android. Please start by reading the Native Modules Intro for an intro to what native modules are.

reactnative.dev

 

https://reactnative.dev/docs/native-modules-ios

 

iOS Native Modules · React Native

Welcome to Native Modules for iOS. Please start by reading the Native Modules Intro for an intro to what native modules are.

reactnative.dev

Native Module 이란?

React Native에서 지원하지 않는, 네이티브(Android, iOS)만의 코드를 이용해 만든 모듈

 

React-Native를 이용해 개발 하다보면, Native의 기능을 사용해야할 경우가 있다.

React-Native는 대체적으로 라이브러리의 의존성이 굉장히 높은 프레임워크다 보니, 라이브러리가 존재하지 않을경우

직접 만들어서 사용해야하는 경우가 있다.

 

안드로이드의 경우 Java/Kotlin이 호환되기에 두가지다 사용할 수 있다. (베이스는 Java)

 

iOS의 경우도 Objective-C/Swift가 호환되기에 두가지다 사용할 수 있다. (베이스는 Objective-C)

->  Bridge Header 파일을 만들어 상호 간의 운용성을 확보

 

https://github.com/Brightbong92/react-native-native-modules-example

 

GitHub - Brightbong92/react-native-native-modules-example

Contribute to Brightbong92/react-native-native-modules-example development by creating an account on GitHub.

github.com

Native Modules 샘플코드 정리

 

https://brightbong.tistory.com/18

 

디바이스 정보를 가져오는 Native Module 만들어보기

Android // DeviceInfoModule.java package com.nativemodule; import androidx.annotation.NonNull; import com.facebook.react.bridge.Promise; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContextBaseJavaModule;

brightbong.tistory.com