Compare commits

..

6 Commits

Author SHA1 Message Date
Marcos Rodriguez Vélez
31d005f93d Add url parameter 2021-09-24 22:28:32 -04:00
Marcos Rodriguez Vélez
951497c678 Use userinfo instead of url 2021-09-24 22:19:40 -04:00
Marcos Rodriguez Vélez
f5becc63f3
Update lifecycle methods 2020-12-17 19:44:33 -05:00
Marcos Rodriguez
05fc7dee38 Fix crash that resulted in passing a string when number was expected. 2019-08-13 19:05:15 -04:00
Marcos Rodriguez
b9e42ec4c4 Fix Podspec 2019-08-13 18:41:27 -04:00
lucarge
8978fac41a [FEAT] - Add podspec to support Cocoapods installations. Refactor Handoff JS class to stop using the deprecated componentWillMount. 2018-09-05 08:53:45 +02:00
5 changed files with 38 additions and 15 deletions

View File

@ -1,7 +0,0 @@
import { Component } from 'react';
export default class Handoff extends Component {
render() {
return null;
}
}

View File

@ -1,19 +1,19 @@
import { Component } from 'react';
import { PureComponent } from 'react';
import { NativeModules } from 'react-native'
const { RNHandoff } = NativeModules;
let id = 0;
export default class Handoff extends Component {
export default class Handoff extends PureComponent {
id = -1;
componentWillMount() {
const { type, title, url } = this.props;
componentDidMount() {
const { type, title, userInfo, url } = this.props;
this.id = ++id;
RNHandoff.becomeCurrent(this.id, type, title, url);
RNHandoff.becomeCurrent(this.id, type, title, userInfo, url);
}
componentWillUnmount() {

7
RNHandoff.js Normal file
View File

@ -0,0 +1,7 @@
import { PureComponent } from 'react'
export default class Handoff extends PureComponent {
render() {
return null
}
}

19
RNHandoff.podspec Normal file
View File

@ -0,0 +1,19 @@
require 'json'
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
Pod::Spec.new do |s|
s.name = "RNHandoff"
s.version = package['version']
s.summary = "React Native Handoff support for iOS"
s.homepage = "https://github.com/IzaakSultan/react-native-handoff"
s.author = "IzaakSultan"
s.license = "MIT"
s.platform = :ios, "9.0"
s.source = { :git => "https://github.com/IzaakSultan/react-native-handoff.git", :tag => s.version.to_s }
s.source_files = "ios/**/*.{h,m}"
s.dependency 'React'
end

View File

@ -12,12 +12,16 @@ NSMutableArray *activities = nil;
return activities;
}
RCT_EXPORT_METHOD(becomeCurrent:(NSNumber * _Nonnull)activityId type:(NSString *)type title:(NSString *)title url:(NSString *)url)
RCT_EXPORT_METHOD(becomeCurrent:(NSNumber * _Nonnull)activityId type:(NSString *)type title:(NSString *)title userInfo:(NSDictionary *)userInfo url:(NSString *)url)
{
NSUserActivity* activity = [[NSUserActivity alloc] initWithActivityType:type];
activity.title = title;
activity.webpageURL = [[NSURL alloc] initWithString:url];
activity.eligibleForHandoff = YES;
if(!([[url stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length] == 0)) {
activity.webpageURL = [NSURL URLWithString:url];
} else {
activity.userInfo = userInfo;
}
[activity becomeCurrent];
[[self activityList] addObject:@{ @"id": activityId, @"activity": activity }];