Please pardon if it is duplicate. I'm developing an app which shares it's post in third party-instagram app using react-native. I searched everywhere and found that there is no such feature available for react-native but it is available in native-ios and native-android. I'm trying to implement in native-ios(objective-c) and found lots of codes for that but I'm little bit confused and can't develop my functionality. Can anyone please explain it step by step here? I've done with linking native-ios files with react-native by doing below code.
.h file
#ifndef Instashare_h
#define Instashare_h
#import "React/RCTBridgeModule.h"
@interface Instashare : NSObject <RCTBridgeModule>
@end
#endif /* Instashare_h */
.m file
#import "Instashare.h"=
#import "React/RCTLog.h"
@implementation Instashare
// This RCT (React) "macro" exposes the current module to JavaScript
RCT_EXPORT_MODULE();
// We must explicitly expose methods otherwise JavaScript can't access anything
RCT_EXPORT_METHOD(get)
{
NSLog(@"explanation code here");
}
@end
React-native.js file
var InstagramShare = NativeModules.Instashare;
export default class ShareComponents extends PureComponent {
_handleInsta = () => {
InstagramShare.get();
}
render{
return(
<TouchableOpacity
onPress={() => this._handleInsta()}
>
<Text>Instagram</Text>
</TouchableOpacity>
);
}
}
A native module is just an Objective-C class that implements the RCTBridgeModule
protocol. If you are wondering, RCT is an abbreviation of ReaCT .
// Instashare.h
#import <React/RCTBridgeModule.h>
@interface Instashare : NSObject <RCTBridgeModule>
@end
React Native will not expose any methods of Instashare to JavaScript unless explicitly told to. This is done using the RCT_EXPORT_METHOD()
macro:
#import "Instashare.h"
#import <React/RCTLog.h>
@implementation Instashare
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(get:(NSString *)name location:(NSString *)location)
{
NSLog(@"explanation code here");
}
@end
Usage
import {NativeModules} from 'react-native';
var Instashare = NativeModules.Instashare;
Instashare.get();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.