This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ios.js
159 lines (143 loc) · 3.74 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
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
TextInput,
View,
Button,
Image
} from 'react-native';
var RCTFH = require('rct-fh');
export default class HelloWorldRN extends Component {
constructor(props) {
console.log('constructor()');
super(props);
this.state = {
message: 'Waiting...',
userInput: '',
init: false
};
}
componentDidMount () {
// After the component mounts we refresh to request data
this.init();
}
sayHello = async () => {
console.log('sayHello');
try {
const result = await RCTFH.cloud({
"path": "/hello", //only the path part of the url, the host will be added automatically
"method": "GET", //all other HTTP methods are supported as well. For example, HEAD, DELETE, OPTIONS
"contentType": "application/json",
"data": { "hello": this.state.userInput}, //data to send to the server
"timeout": 25000 // timeout value specified in milliseconds. Default: 60000 (60s)
});
console.log('sayHello result', result);
if (result && result.msg)
this.setState({message: result.msg});
else
this.setState({message: JSON.stringify(result)});
} catch (e) {
this.setState({message: 'Error' + e});
}
}
init = async () => {
try {
this.setState({message: 'Initializing...'});
const result = await RCTFH.init();
console.log('init result', result);
this.setState({message: 'Ready'});
if (result === 'SUCCESS') {
console.log('SUCCESS');
this.setState({init: true});
} else {
console.error('Error');
}
} catch (e) {
console.error('Exception', e);
}
}
updateUserInput = async (userInput) => {
this.setState({userInput: userInput});
}
render() {
return (
<View style={styles.container}>
<Text style={styles.h1}>
Feed Henry - React Native Template
</Text>
<TextInput key='2' style={styles.input} autoCapitalize = 'none'
onSubmitEditing={(event) => this.updateUserInput(event.nativeEvent.text)}
onEndEditing={(event) => this.updateUserInput(event.nativeEvent.text)}
placeholder='Enter Your Name Here'
placeholderTextColor='grey'
/>
<Button style={styles.button}
disabled={!this.state.init}
onPress={this.sayHello}
title="Say Hello From The Cloud"
accessibilityLabel="Say Hello From The Cloud"
/>
<View style={{flex: 1, flexDirection: 'row', alignItems: 'flex-start'}}>
<Text style={styles.message}>
{this.state.message}
</Text>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container_1: {
paddingTop: 23,
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
container: {
paddingTop: 23,
flex: 1,
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
},
row: {
flex: 1,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
},
input: {
margin: 30,
height: 36,
padding: 4,
fontSize: 18,
borderWidth: 1,
borderColor: 'black',
borderRadius: 8,
color: 'black'
},
h1: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
message: {
flex: 1,
height: 150,
fontSize: 20,
textAlign: 'center',
margin: 10,
color: 'grey',
borderWidth: 1,
borderColor: 'grey',
},
});
AppRegistry.registerComponent('HelloWorldRN', () => HelloWorldRN);