@shoutem/ui 5.0.1 → 5.1.0
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/components/ListView.js +0 -5
- package/index.js +7 -0
- package/init.js +7 -1
- package/package.json +1 -1
- package/services/index.js +6 -0
- package/services/variableResolver.js +73 -0
- package/theme.js +2247 -2184
package/components/ListView.js
CHANGED
|
@@ -152,11 +152,6 @@ class ListView extends PureComponent {
|
|
|
152
152
|
// data to display
|
|
153
153
|
mappedProps.data = data;
|
|
154
154
|
|
|
155
|
-
// key extractor
|
|
156
|
-
if (!keyExtractor) {
|
|
157
|
-
mappedProps.keyExtractor = (item, index) => index.toString();
|
|
158
|
-
}
|
|
159
|
-
|
|
160
155
|
// sections for SectionList
|
|
161
156
|
if (sections) {
|
|
162
157
|
mappedProps.sections = sections;
|
package/index.js
CHANGED
|
@@ -21,6 +21,13 @@ export {
|
|
|
21
21
|
resolveFontStyle,
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
+
export {
|
|
25
|
+
ThemeVariableResolver,
|
|
26
|
+
defaultResolver as variableResolver,
|
|
27
|
+
resolveVariable,
|
|
28
|
+
createScopedResolver,
|
|
29
|
+
} from './services';
|
|
30
|
+
|
|
24
31
|
// Components
|
|
25
32
|
export { ActionSheet } from './components/ActionSheet';
|
|
26
33
|
export { View } from './components/View';
|
package/init.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { Theme } from '@shoutem/theme';
|
|
2
|
-
import
|
|
2
|
+
import {
|
|
3
|
+
defaultResolver as variableResolver,
|
|
4
|
+
} from './services';
|
|
5
|
+
import getThemeStyle, { defaultThemeVariables } from './theme';
|
|
3
6
|
|
|
4
7
|
function setDefaultThemeStyle() {
|
|
8
|
+
variableResolver.setVariables(defaultThemeVariables)
|
|
9
|
+
|
|
5
10
|
const theme = getThemeStyle();
|
|
11
|
+
|
|
6
12
|
Theme.setDefaultThemeStyle(theme);
|
|
7
13
|
}
|
|
8
14
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import autoBind from 'auto-bind';
|
|
3
|
+
|
|
4
|
+
const THEME_EXTENSION_SCOPE = 'shoutem.theme';
|
|
5
|
+
|
|
6
|
+
export class ThemeVariableResolver {
|
|
7
|
+
constructor(variables) {
|
|
8
|
+
this.variables = { ...variables };
|
|
9
|
+
|
|
10
|
+
autoBind(this);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
setVariables(variables) {
|
|
14
|
+
this.variables = { ...variables };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
getScopedVariable(scope, variable) {
|
|
18
|
+
if (!this.variables || _.isEmpty(this.variables)) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
'Theme variable resolver not yet initialised. Please call `setVariables` prior to this function call',
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const scopePath = _.split(scope, '.');
|
|
25
|
+
const variablePath = _.split(variable, '.');
|
|
26
|
+
|
|
27
|
+
return _.get(
|
|
28
|
+
this.variables,
|
|
29
|
+
[...scopePath, ...variablePath],
|
|
30
|
+
_.get(this.variables, variablePath)
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Currently supports 2 function signatures
|
|
35
|
+
// resolveVariable(variableName) -> Tries to get the variable under the root scope ( generic theme values )
|
|
36
|
+
// resolveVariable(scope, variableName) -> Tries to get the variable under specific scope
|
|
37
|
+
// Variable name can be stringified object path or a regular string, i.e -> text.color
|
|
38
|
+
resolveVariable(...params) {
|
|
39
|
+
if (arguments.length === 1) {
|
|
40
|
+
const variablePath = _.split(params[0], '.');
|
|
41
|
+
|
|
42
|
+
return _.get(this.variables, variablePath);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (arguments.length === 2) {
|
|
46
|
+
return this.getScopedVariable(params[0], params[1]);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
throw new Error(
|
|
50
|
+
"Invalid theme variable resolution call. Please use full signature \n-> resolveVariable(scope, variableName),\n or the shorthand if you're getting a variable from shoutem.theme extension \n->resolveVariable(variableName)",
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
createScopedResolver(scope) {
|
|
55
|
+
return (...params) => {
|
|
56
|
+
if (params.length === 1) {
|
|
57
|
+
return this.getScopedVariable(scope, params[0]);
|
|
58
|
+
}
|
|
59
|
+
if (params.length === 2) {
|
|
60
|
+
return this.getScopedVariable(params[0], params[1]);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return undefined;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Expose both, the resolver service, and the default resolver working with
|
|
69
|
+
// shoutem default theme. This way the logic can be used for multiple themes/resolvers, or
|
|
70
|
+
// if needed, you can override the default theme variables using the setVariables method
|
|
71
|
+
export const defaultResolver = new ThemeVariableResolver();
|
|
72
|
+
export const resolveVariable = defaultResolver.resolveVariable;
|
|
73
|
+
export const createScopedResolver = defaultResolver.createScopedResolver;
|