Skip to content

Commit

Permalink
Modernise and fix RN deprecation warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdmunro committed Jan 20, 2018
1 parent 1e3b0f8 commit e9d0c3c
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 15 deletions.
13 changes: 5 additions & 8 deletions example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,27 @@ import {
Image,
} from 'react-native';
import SpotlightSearch from 'react-native-spotlight-search';
import banana from './banana.png'
import strawberry from './strawberry.png'
import kiwi from './kiwi.png'

const sampleFruits = [
{
name: 'Strawberry',
details: 'A sweet and juicy fruit.',
key: '1',
image: strawberry,
image: 'strawberry',
keywords: ['delicious', 'edible'],
},
{
name: 'Banana',
details: 'A bright yellow fruit.',
key: '2',
image: banana,
image: 'banana',
keywords: ['plantain'],
},
{
name: 'Kiwi',
details: 'Not a type of bird.',
key: '3',
image: kiwi,
image: 'kiwi',
keywords: ['new zeland'],
},
];
Expand All @@ -47,7 +44,7 @@ const indexSearchableItems = (() => {
title: fruit.name,
contentDescription: fruit.details,
uniqueIdentifier: fruit.key,
thumbnailUri: fruit.image.path,
thumbnailName: fruit.image,
keywords: fruit.keywords,
};
}));
Expand Down Expand Up @@ -90,7 +87,7 @@ const FruitRow = ({fruit}) => (
<View style={styles.row}>
<Image resizeMode={Image.resizeMode.contain}
style={styles.rowImage}
source={fruit.image}/>
source={{uri: fruit.image}}/>
<View style={styles.rowTextContainer}>
<Text style={styles.rowTitle}>{fruit.name}</Text>
<Text style={styles.rowDescription}>{fruit.details}</Text>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
Expand Down Expand Up @@ -29,6 +39,11 @@
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
}
],
"info" : {
Expand Down
2 changes: 1 addition & 1 deletion example/ios/example/Images.xcassets/Contents.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"version" : 1,
"author" : "xcode"
}
}
}
21 changes: 21 additions & 0 deletions example/ios/example/Images.xcassets/banana.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "banana.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions example/ios/example/Images.xcassets/kiwi.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "kiwi.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "strawberry.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {NativeModules, NativeAppEventEmitter} from 'react-native';
import {NativeModules, NativeEventEmitter} from 'react-native';

const {SpotlightSearch} = NativeModules;

SpotlightSearch.searchItemTapped = (callback) => NativeAppEventEmitter.addListener('spotlightSearchItemTapped', callback);
const spotlightEventEmitter = new NativeEventEmitter(SpotlightSearch);

SpotlightSearch.searchItemTapped = (callback) => spotlightEventEmitter.addListener('spotlightSearchItemTapped', callback);

export default SpotlightSearch;
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>

@interface RCTSpotlightSearch : NSObject <RCTBridgeModule>
@interface RCTSpotlightSearch : RCTEventEmitter <RCTBridgeModule>

+ (void)handleContinueUserActivity:(NSUserActivity *)userActivity;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ + (BOOL)requiresMainQueueSetup {
return YES;
}

- (dispatch_queue_t)methodQueue
{
- (NSArray<NSString *> *)supportedEvents {
return @[kSpotlightSearchItemTapped];
}

- (dispatch_queue_t)methodQueue {
return dispatch_get_main_queue();
}

Expand Down Expand Up @@ -97,7 +100,7 @@ - (void)handleContinueUserActivity:(NSUserActivity *)userActivity {
return;
}

[self.bridge.eventDispatcher sendAppEventWithName:kSpotlightSearchItemTapped body:uniqueItemIdentifier];
[self sendEventWithName:kSpotlightSearchItemTapped body:uniqueItemIdentifier];
}

RCT_EXPORT_METHOD(indexItem:(NSDictionary *)item resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
Expand Down

0 comments on commit e9d0c3c

Please sign in to comment.