-
Notifications
You must be signed in to change notification settings - Fork 0
/
LauncherScreen.tsx
70 lines (57 loc) 路 1.72 KB
/
LauncherScreen.tsx
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
import { BlueBase, BlueBaseContext, Plugin, Theme, getComponent } from '@bluebase/core';
import { ScrollView, StyleProp, ViewStyle } from 'react-native';
import { AppGrid } from '../AppGrid';
import React from 'react';
import { View } from '@bluebase/components';
import { Wallpaper } from '../Wallpaper';
const EmptyState = getComponent('LauncherEmptyState', 'EmptyState');
export interface LauncherScreenStyles {
root: StyleProp<ViewStyle>;
}
export interface LauncherScreenProps {
styles?: LauncherScreenStyles;
}
export interface LauncherScreenState {
plugins: Plugin[];
}
export class LauncherScreen extends React.PureComponent<LauncherScreenProps, LauncherScreenState> {
static contextType = BlueBaseContext;
readonly state: LauncherScreenState = {
plugins: [],
};
static defaultStyles = (theme: Theme) => ({
root: {
flex: 1,
paddingHorizontal: theme.spacing.unit * 2,
},
})
async componentWillMount() {
const BB: BlueBase = this.context;
const enabledPlugins = await BB.Plugins.getAllEnabled();
const plugins = enabledPlugins.filter(p => !!p.indexRoute);
this.setState({ plugins });
}
render() {
const BB: BlueBase = this.context;
const { styles } = this.props;
const { plugins } = this.state;
if (!plugins || plugins.length === 0) {
return (
<View testID="view" style={{ flex: 1 }}>
<EmptyState />
</View>
);
}
return (
<Wallpaper
portraitProps={BB.Configs.getValue('plugin.launcher.wallpaper.portrait')}
landscapeProps={BB.Configs.getValue('plugin.launcher.wallpaper.landscape')}
defaultProps={BB.Configs.getValue('plugin.launcher.wallpaper')}
>
<ScrollView style={styles!.root}>
<AppGrid plugins={plugins} />
</ScrollView>
</Wallpaper>
);
}
}