@sleeperhq/mini-core 1.4.0 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/build_mini.js CHANGED
@@ -40,7 +40,7 @@ const getCommands = (projectName) => {
40
40
 
41
41
  const getBundleCommand = (platform) => {
42
42
  return `node "${reactNativeCliPath}" webpack-bundle \
43
- --entry-file index.tsx \
43
+ --entry-file ./node_modules/@sleeperhq/mini-core/start.tsx \
44
44
  --platform ${platform} \
45
45
  --dev false \
46
46
  --reset-cache \
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sleeperhq/mini-core",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "Core library frameworks for developing Sleeper Mini Apps.",
5
5
  "main": "index.ts",
6
6
  "types": "index.d.ts",
package/start.tsx ADDED
@@ -0,0 +1,87 @@
1
+ import React, {useCallback, useState} from 'react';
2
+ import {
3
+ AppRegistry,
4
+ ActivityIndicator,
5
+ Text,
6
+ View,
7
+ StyleSheet,
8
+ SafeAreaView,
9
+ } from 'react-native';
10
+ import {DevServer, Types} from '.';
11
+
12
+ import 'root/package_list';
13
+ import config from 'root/app.json';
14
+ import Project from 'app';
15
+
16
+ DevServer.init(config);
17
+
18
+ const Root = () => {
19
+ const [context, setContext] = useState<Types.Context>({} as Types.Context);
20
+ const [connected, setConnected] = useState<boolean>(false);
21
+ const [, updateState] = React.useState<any>();
22
+ const forceUpdate = React.useCallback(() => updateState({}), []);
23
+
24
+ const _onContextChanged = useCallback((data: Types.Context) => {
25
+ setContext(data);
26
+ }, []);
27
+
28
+ const _onContextUpdated = useCallback(
29
+ (data: any) => {
30
+ setContext(existing => {
31
+ for (const key in data) {
32
+ existing[key] = data[key];
33
+ }
34
+ return existing;
35
+ });
36
+ forceUpdate();
37
+ },
38
+ [forceUpdate],
39
+ );
40
+
41
+ const _onConnected = useCallback((value: boolean) => {
42
+ setConnected(value);
43
+ }, []);
44
+
45
+ const _renderWaitingForConnection = () => {
46
+ return (
47
+ <View style={styles.loadingContainer}>
48
+ <Text style={styles.loadingText}>Waiting for connection...</Text>
49
+ <ActivityIndicator size={50} />
50
+ <Text style={styles.loadingText}>
51
+ Make sure to update app.json with your phone's IP address.
52
+ </Text>
53
+ </View>
54
+ );
55
+ };
56
+
57
+ return (
58
+ <SafeAreaView style={styles.container}>
59
+ <DevServer
60
+ onContextChanged={_onContextChanged}
61
+ onContextUpdated={_onContextUpdated}
62
+ onConnected={_onConnected}
63
+ />
64
+ {connected && <Project context={context} />}
65
+ {!connected && _renderWaitingForConnection()}
66
+ </SafeAreaView>
67
+ );
68
+ };
69
+
70
+ const styles = StyleSheet.create({
71
+ container: {
72
+ flex: 1,
73
+ backgroundColor: '#18202f',
74
+ },
75
+ loadingText: {
76
+ color: 'white',
77
+ fontSize: 20,
78
+ textAlign: 'center',
79
+ },
80
+ loadingContainer: {
81
+ flex: 1,
82
+ alignItems: 'center',
83
+ justifyContent: 'center',
84
+ },
85
+ });
86
+
87
+ AppRegistry.registerComponent(config.name, () => Root);
package/webpack.config.js CHANGED
@@ -31,8 +31,8 @@ const sampleClassPathLocal = `./src/${samples[selectedSample]}`
31
31
  module.exports = env => {
32
32
  const {
33
33
  mode = 'development',
34
- context = __dirname,
35
- entry = './index.tsx',
34
+ context = path.resolve(__dirname, '..', '..', '..'),
35
+ entry = './node_modules/@sleeperhq/mini-core/start.tsx',
36
36
  platform,
37
37
  minimize = mode === 'production',
38
38
  devServer = undefined,
@@ -109,6 +109,7 @@ module.exports = env => {
109
109
  // },
110
110
  alias: {
111
111
  app: path.resolve(__dirname, sampleClassPath),
112
+ root: path.resolve(__dirname, '..', '..', '..'),
112
113
  },
113
114
  },
114
115
  /**