This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AuthInterceptor extends InterceptorsWrapper { | |
final Dio dio; | |
AuthInterceptor(this.dio); | |
// when accessToken is expired & having multiple requests call | |
// this variable to lock others request to make sure only trigger call refresh token 01 times | |
// to prevent duplicate refresh call | |
bool _isRefreshing = false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RNViewManager: NSObject { | |
var bridge: RCTBridge? | |
static let sharedInstance = RNViewManager() | |
func createBridgeIfNeeded() -> RCTBridge { | |
if bridge == nil { | |
bridge = RCTBridge.init(delegate: self, launchOptions: nil) | |
} | |
return bridge! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Send a message to native code | |
TestConnectNative.sendMessage(this.state.messageToNative); | |
// Send a callback to native code and receive a message from it | |
TestConnectNative.sendCallback((nativeMessage) => { | |
console.log(`This log is from js code callback with native message: "${nativeMessage}"`); | |
}); | |
// Exit RN to go back to native | |
TestConnectNative.exitRN(rootTag); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// If TestConnectNative is an package from npm, you can think this is index.js file | |
import {NativeModules, Platform} from 'react-native'; | |
const testConnectNative = NativeModules.TestConnectNative; | |
const TestConnectNative = { | |
sendMessage: msg => { | |
testConnectNative.sendMessageToNative(msg); | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// If TestConnectNative is an package from npm, you can think this is index.js file | |
import {BackHandler, NativeModules, Platform} from 'react-native'; | |
const testConnectNative = NativeModules.TestConnectNative; | |
const TestConnectNative = { | |
sendMessage: msg => { | |
testConnectNative.sendMessageToNative(msg); | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <React/RCTBridgeModule.h> | |
@interface RCT_EXTERN_REMAP_MODULE(TestConnectNative, TestConnectNativeModule, NSObject) | |
RCT_EXTERN_METHOD(sendMessageToNative: (NSString)rnMessage) | |
RCT_EXTERN_METHOD(sendCallbackToNative: (RCTResponseSenderBlock)rnCallback) | |
RCT_EXTERN_METHOD(goToSecondViewController: (nonnull NSNumber *)reactTag) | |
RCT_EXTERN_METHOD(dismissViewController: (nonnull NSNumber *)reactTag) | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <React/RCTBridgeModule.h> | |
#import <React/RCTViewManager.h> | |
#import <React/RCTBridge.h> | |
#import <React/RCTUIManager.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@objc(TestConnectNativeModule) | |
class TestConnectNativeModule: NSObject { | |
@objc | |
static func requiresMainQueueSetup() -> Bool { | |
return true | |
} | |
@objc | |
func sendMessageToNative(_ rnMessage: String) { | |
print("This log is from swift: \(rnMessage)") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestConnectNativePackage : ReactPackage { | |
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> { | |
return emptyList() | |
} | |
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> { | |
val modules: MutableList<NativeModule> = ArrayList() | |
modules.add(TestConnectNativeModule(reactContext)) | |
return modules | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestConnectNativeModule internal constructor(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) { | |
override fun getName(): String { | |
return "TestConnectNative" | |
} | |
@ReactMethod | |
fun sendMessageToNative(rnMessage: String?) { | |
Log.d("This log is from java", rnMessage) | |
} |
NewerOlder