Skip to content

Commit

Permalink
Merge pull request #10 from jdmunro/modernise
Browse files Browse the repository at this point in the history
Support for modern React Native versions
  • Loading branch information
jdmunro authored Jan 20, 2018
2 parents 067b53a + 85f0bcb commit 9f52589
Show file tree
Hide file tree
Showing 66 changed files with 6,687 additions and 277 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/node_modules/
*.xcuserstate

\.DS_Store
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
example/*
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ SpotlightSearch.indexItems([
contentDescription: 'A sweet and juicy fruit.',
uniqueIdentifier: '1',
domain: 'fruit',
thumbnailUri: require('image!strawberry').path,
thumbnailName: 'strawberry',
},
{
title: 'Kiwi',
contentDescription: 'Not a type of bird.',
uniqueIdentifier: '2',
domain: 'fruit',
thumbnailUri: require('kiwi!strawberry').path,
thumbnailName: 'kiwi',
},
]);
```
Expand All @@ -85,7 +85,7 @@ SpotlightSearch.indexItem({
title: 'Strawberry',
contentDescription: 'A sweet and juicy fruit.',
uniqueIdentifier: '1',
thumbnailUri: require('image!strawberry').path,
thumbnailName: 'strawberry',
});
```

Expand All @@ -97,7 +97,7 @@ SpotlightSearch.indexItem({
|**`contentDescription`**|A description which appears below the title in the search results.|`string`|No|
|**`uniqueIdentifier`**|A unique and stable identifier. Used to refer to the item. |`string`|Yes|
|**`domain`**|A string for grouping related items together in a way that makes sense. Not displayed to the user. |`string`|Yes|
|**`thumbnailUri`**|A local file URI to a thumbnail image. See [A Note About Thumbnails](#a-note-about-thumbnails).|`string`|No|
|**`thumbnailName`**|A local file name/key to a thumbnail image. See [A Note About Thumbnails](#a-note-about-thumbnails).|`string`|No|
|**`keywords`**|An array of keywords which can be used to help inform the search index. Not visible to the user.|`[string]`|No|

### Updating Items
Expand Down Expand Up @@ -134,7 +134,7 @@ SpotlightSearch.deleteAllItems().then(() => {
title: 'Strawberry',
contentDescription: 'A sweet and juicy fruit.',
uniqueIdentifier: '1',
thumbnailUri: require('image!strawberry').path,
thumbnailName: 'strawberry',
});
});
```
Expand All @@ -153,9 +153,9 @@ The parameter will be the ```uniqueIdentifier``` that the item was indexed with.

## A Note About Thumbnails

Currently, in order to use an image it must exist locally on the device.
Currently, in order to use an image it must exist locally on the device. This is a limitation of iOS rather than of this library.

This means it is not possible to use images hosted on the web. Additionally, there is a limitation that you cannot use a statically imported image managed by React Native. Instead, you _must_ manually add the image to your app's asset catalog or alternatively use an image that is created within the app which you can access the URI of.
This means it is not possible to use images hosted on the web. Additionally, there is a limitation that you cannot use a statically imported image managed by React Native. Instead, you _must_ manually add the image to your app's asset catalog.

Suggestions on how to improve this are welcome!

Expand Down
3 changes: 3 additions & 0 deletions example/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["react-native"]
}
File renamed without changes.
56 changes: 56 additions & 0 deletions example/.flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[ignore]
; We fork some components by platform
.*/*[.]android.js

; Ignore "BUCK" generated dirs
<PROJECT_ROOT>/\.buckd/

; Ignore unexpected extra "@providesModule"
.*/node_modules/.*/node_modules/fbjs/.*

; Ignore duplicate module providers
; For RN Apps installed via npm, "Libraries" folder is inside
; "node_modules/react-native" but in the source repo it is in the root
.*/Libraries/react-native/React.js

; Ignore polyfills
.*/Libraries/polyfills/.*

; Ignore metro
.*/node_modules/metro/.*

[include]

[libs]
node_modules/react-native/Libraries/react-native/react-native-interface.js
node_modules/react-native/flow/
node_modules/react-native/flow-github/

[options]
emoji=true

module.system=haste

munge_underscores=true

module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'

module.file_ext=.js
module.file_ext=.jsx
module.file_ext=.json
module.file_ext=.native.js

suppress_type=$FlowIssue
suppress_type=$FlowFixMe
suppress_type=$FlowFixMeProps
suppress_type=$FlowFixMeState

suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError

unsafe.enable_getters_and_setters=true

[version]
^0.61.0
1 change: 1 addition & 0 deletions example/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pbxproj -text
53 changes: 53 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# OSX
#
.DS_Store

# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
project.xcworkspace

# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml

# node.js
#
node_modules/
npm-debug.log
yarn-error.log

# BUCK
buck-out/
\.buckd/
*.keystore

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/

*/fastlane/report.xml
*/fastlane/Preview.html
*/fastlane/screenshots
File renamed without changes.
21 changes: 10 additions & 11 deletions example/example/index.ios.js → example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ const sampleFruits = [
name: 'Strawberry',
details: 'A sweet and juicy fruit.',
key: '1',
image: require('image!strawberry'),
image: 'strawberry',
keywords: ['delicious', 'edible'],
},
{
name: 'Banana',
details: 'A bright yellow fruit.',
key: '2',
image: require('image!banana'),
image: 'banana',
keywords: ['plantain'],
},
{
name: 'Kiwi',
details: 'Not a type of bird.',
key: '3',
image: require('image!kiwi'),
image: 'kiwi',
keywords: ['new zeland'],
},
];
Expand All @@ -44,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 All @@ -53,19 +53,18 @@ const indexSearchableItems = (() => {
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
paddingLeft: 10,
paddingRight: 10,
},
introText: {
marginTop: 64,
},
row: {
flex: 1,
height: 120,
flexDirection: 'row',
alignItems: 'center',
paddingLeft: 10,
paddingRight: 10,
},
rowTextContainer: {
flex: 1,
Expand All @@ -88,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 All @@ -98,12 +97,12 @@ const FruitRow = ({fruit}) => (

const Example = () => (
<View style={styles.container}>
<Text style={styles.introText}>The items below have been added to the Spotlight search index on this device</Text>
<Text style={styles.introText}>The items below have been added to the Spotlight search index on this device.</Text>
{sampleFruits.map((fruit) => (
<FruitRow key={fruit.key}
fruit={fruit}/>
))}
</View>
);

AppRegistry.registerComponent('example', () => Example);
export default Example;
12 changes: 12 additions & 0 deletions example/__tests__/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'react-native';
import React from 'react';
import App from '../App';

// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';

it('renders correctly', () => {
const tree = renderer.create(
<App />
);
});
65 changes: 65 additions & 0 deletions example/android/app/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# To learn about Buck see [Docs](https://buckbuild.com/).
# To run your application with Buck:
# - install Buck
# - `npm start` - to start the packager
# - `cd android`
# - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"`
# - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck
# - `buck install -r android/app` - compile, install and run application
#

lib_deps = []

for jarfile in glob(['libs/*.jar']):
name = 'jars__' + jarfile[jarfile.rindex('/') + 1: jarfile.rindex('.jar')]
lib_deps.append(':' + name)
prebuilt_jar(
name = name,
binary_jar = jarfile,
)

for aarfile in glob(['libs/*.aar']):
name = 'aars__' + aarfile[aarfile.rindex('/') + 1: aarfile.rindex('.aar')]
lib_deps.append(':' + name)
android_prebuilt_aar(
name = name,
aar = aarfile,
)

android_library(
name = "all-libs",
exported_deps = lib_deps,
)

android_library(
name = "app-code",
srcs = glob([
"src/main/java/**/*.java",
]),
deps = [
":all-libs",
":build_config",
":res",
],
)

android_build_config(
name = "build_config",
package = "com.example",
)

android_resource(
name = "res",
package = "com.example",
res = "src/main/res",
)

android_binary(
name = "app",
keystore = "//android/keystores:debug",
manifest = "src/main/AndroidManifest.xml",
package_type = "debug",
deps = [
":app-code",
],
)
Loading

0 comments on commit 9f52589

Please sign in to comment.