-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ios.js
171 lines (136 loc) · 5.35 KB
/
index.ios.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
'use strict';
import Relay from 'react-relay';
Relay.injectNetworkLayer(
new Relay.DefaultNetworkLayer('https://metaphysics-staging.artsy.net')
// headers: {
// Authorization: 'Basic SSdsbCBmaW5kIHNvbWV0aGluZyB0byBwdXQgaGVyZQ==',
// })
);
// if (!__DEV__) {
// Relay.injectNetworkLayer(new Relay.DefaultNetworkLayer('https://metaphysics-staging.artsy.net'));
// } else {
// let printRelayQuery = require('react-relay/lib/printRelayQuery');
// class DebugNetworkLayer extends Relay.DefaultNetworkLayer {
// sendQueries(requests) {
// requests.forEach(request => {
// let originalResolve = request.resolve;
// request.resolve = data => {
// console.log(data);
// originalResolve(data);
// }
// console.log('[RELAY Request] ' + printRelayQuery(request._query).text);
// })
// return super.sendQueries(requests);
// }
// }
// Relay.injectNetworkLayer(new DebugNetworkLayer('https://metaphysics-staging.artsy.net'));
// }
class ArtistRoute extends Relay.Route {
static queries = {
artist: () => Relay.QL`
query { artist(id: $artistID) }
`,
};
static paramDefinitions = {
artistID: { required: true },
};
static routeName = 'ArtistRoute';
}
let banksyRoute = new ArtistRoute({ artistID: 'banksy' });
import React, {
Text,
TouchableHighlight,
View,
ScrollView,
NativeModules,
ActivityIndicatorIOS,
} from 'react-native';
// Disable the native polyfill during development, which will make network requests show-up in the Chrome dev-tools.
// Specifically, in our case, we get to see the Relay requests.
//
// It will be `undefined` unless running inside Chrome.
//
// See:
// * https://github.com/facebook/react-native/blob/2d0051f21371e8a51fde836c62a474a941023dd4/Libraries/JavaScriptAppEngine/Initialization/InitializeJavaScriptAppEngine.js#L41-L56
// * https://github.com/facebook/react-native/issues/934
//
if (__DEV__ && global.originalXMLHttpRequest != undefined) {
global.XMLHttpRequest = global.originalXMLHttpRequest;
}
var styles = React.StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'white'
},
});
// TODO: I tried adding the components dir to the package manager with the `--root` option,
// but to no avail, so using this relative style for now.
import ARArtworksMasonryGrid from '../ARComponents/ARArtworksMasonryGridComponent';
//debugger;
class SimpleApp extends React.Component {
pushReactViewController() {
console.log('Host VC: 0x' + this.props.viewControllerID.toString(16));
NativeModules.ARNavigatorModule.pushViewController('/react-controller',
true,
this.props.viewControllerID);
}
pushNativeViewController() {
console.log('Host VC: 0x' + this.props.viewControllerID.toString(16));
NativeModules.ARNavigatorModule.pushViewController('/native-controller',
true,
this.props.viewControllerID);
}
render() {
return (
<View style={styles.container}>
<TouchableHighlight onPress={this.pushReactViewController.bind(this)}>
<Text>Tap to add a React VC to the navigation stack.</Text>
</TouchableHighlight>
<TouchableHighlight onPress={this.pushNativeViewController.bind(this)}>
<Text>Tap to add a Native VC to the navigation stack.</Text>
</TouchableHighlight>
<ScrollView>
<ARArtworksMasonryGrid artist={this.props.artist} rank={3} dimensionLength={120} itemMargins={{ width: 20, height: 10 }} />
<Text>This should be just below the grid!</Text>
</ScrollView>
{/* This makes the collection view have a height of 300 points, and shows the label directly underneath it.
<ARArtworksMasonryGrid style={{ height: 300 }} artist={this.props.artist} rank={3} dimensionLength={120} itemMargins={{ width: 20, height: 10 }} />
<Text>This should be just below the grid!</Text>
*/}
{/* This makes the collection view fill the available height, while leaving place for the label underneath it.
<ARArtworksMasonryGrid style={{ flex: 1 }} artist={this.props.artist} rank={3} dimensionLength={120} itemMargins={{ width: 20, height: 10 }} />
<Text>This should be just below the grid!</Text>
*/}
</View>
);
}
}
let SimpleAppContainer = Relay.createContainer(SimpleApp, {
fragments: {
artist: () => Relay.QL`
fragment on Artist {
${ARArtworksMasonryGrid.getFragment('artist')}
}
`,
}
});
class SimpleRelayApp extends React.Component {
render() {
// https://facebook.github.io/relay/docs/guides-root-container.html
return <Relay.RootContainer
Component={SimpleAppContainer}
route={banksyRoute}
renderLoading={() => {
return <ActivityIndicatorIOS
style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}
size="large"
color="black"
/>;
}}
renderFailure={(error, retry) => {
return <Text>Failed to load.</Text>
}}
/>;
}
}
React.AppRegistry.registerComponent('SimpleApp', () => SimpleRelayApp);