-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(react-native): use View as a container for react-native (#1729)
fixes #1730 Also fixes: - http://stackoverflow.com/questions/41064940/using-algolia-react-instantsearch-with-react-native - http://stackoverflow.com/questions/41066380/react-native-algolia-instantsearch-expected-a-component-class-got-object-objec
- Loading branch information
Showing
43 changed files
with
2,113 additions
and
96 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["react-native"] | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/react-instantsearch/examples/reactnative/.buckconfig
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
[android] | ||
target = Google Inc.:Google APIs:23 | ||
|
||
[maven_repositories] | ||
central = https://repo1.maven.org/maven2 |
1 change: 1 addition & 0 deletions
1
packages/react-instantsearch/examples/reactnative/.gitattributes
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.pbxproj -text |
42 changes: 42 additions & 0 deletions
42
packages/react-instantsearch/examples/reactnative/.gitignore
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# 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 | ||
|
||
# BUCK | ||
buck-out/ | ||
\.buckd/ | ||
android/app/libs | ||
*.keystore |
103 changes: 103 additions & 0 deletions
103
packages/react-instantsearch/examples/reactnative/App.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/** | ||
* Sample React Native App | ||
* https://github.com/facebook/react-native | ||
* @flow | ||
*/ | ||
|
||
import React from 'react'; | ||
import { | ||
StyleSheet, | ||
Text, | ||
View, | ||
ListView, | ||
TextInput, | ||
Image, | ||
} from 'react-native'; | ||
import {InstantSearch} from 'react-instantsearch/native'; | ||
import {connectSearchBox, connectInfiniteHits} from 'react-instantsearch/connectors'; | ||
|
||
const styles = StyleSheet.create({ | ||
maincontainer: { | ||
paddingTop: 20, | ||
paddingBottom: 10, | ||
}, | ||
item: { | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
backgroundColor: 'white', | ||
}, | ||
}); | ||
|
||
export default React.createClass({ | ||
render() { | ||
return ( | ||
<View style={styles.maincontainer}> | ||
<InstantSearch | ||
className="container-fluid" | ||
appId="latency" | ||
apiKey="6be0576ff61c053d5f9a3225e2a90f76" | ||
indexName="ikea" | ||
> | ||
<ConnectedSearchBox/> | ||
<ConnectedHits/> | ||
</InstantSearch> | ||
</View> | ||
); | ||
}, | ||
}); | ||
|
||
class SearchBox extends React.Component { | ||
render() { | ||
return <TextInput | ||
style={{height: 40, borderColor: 'gray', borderWidth: 1}} | ||
onChangeText={text => this.props.refine(text)} | ||
value={this.props.currentRefinement} | ||
/>; | ||
} | ||
} | ||
|
||
SearchBox.propTypes = { | ||
refine: React.PropTypes.func.isRequired, | ||
currentRefinement: React.PropTypes.string, | ||
}; | ||
|
||
const ConnectedSearchBox = connectSearchBox(SearchBox); | ||
|
||
class Hits extends React.Component { | ||
onEndReached = () => { | ||
if (this.props.hasMore) { | ||
this.props.refine(); | ||
} | ||
}; | ||
|
||
render() { | ||
const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}); | ||
const hits = this.props.hits.length > 0 ? | ||
<View > | ||
<ListView | ||
dataSource={ds.cloneWithRows(this.props.hits)} | ||
renderRow={this._renderRow} | ||
onEndReached={this.onEndReached}/> | ||
</View> : null; | ||
return hits; | ||
} | ||
|
||
_renderRow = hit => | ||
<View style={styles.item}> | ||
<Image | ||
style={{height: 100, width: 100}} | ||
source={{uri: hit.image}} | ||
/> | ||
<Text> | ||
{hit.name} | ||
</Text> | ||
</View>; | ||
} | ||
|
||
Hits.propTypes = { | ||
hits: React.PropTypes.array.isRequired, | ||
refine: React.PropTypes.func.isRequired, | ||
hasMore: React.PropTypes.bool.isRequired, | ||
}; | ||
|
||
const ConnectedHits = connectInfiniteHits(Hits); |
66 changes: 66 additions & 0 deletions
66
packages/react-instantsearch/examples/reactnative/android/app/BUCK
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import re | ||
|
||
# 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__' + re.sub(r'^.*/([^/]+)\.jar$', r'\1', jarfile) | ||
lib_deps.append(':' + name) | ||
prebuilt_jar( | ||
name = name, | ||
binary_jar = jarfile, | ||
) | ||
|
||
for aarfile in glob(['libs/*.aar']): | ||
name = 'aars__' + re.sub(r'^.*/([^/]+)\.aar$', r'\1', aarfile) | ||
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.reactnative', | ||
) | ||
|
||
android_resource( | ||
name = 'res', | ||
res = 'src/main/res', | ||
package = 'com.reactnative', | ||
) | ||
|
||
android_binary( | ||
name = 'app', | ||
package_type = 'debug', | ||
manifest = 'src/main/AndroidManifest.xml', | ||
keystore = '//android/keystores:debug', | ||
deps = [ | ||
':app-code', | ||
], | ||
) |
Oops, something went wrong.