Skip to content

Commit f351186

Browse files
committed
feat: Update Acrylic and StyleManager
1 parent 1648736 commit f351186

File tree

9 files changed

+116
-62
lines changed

9 files changed

+116
-62
lines changed

docs/src/components/CodeExample.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface DataProps {
1414
doubleThemeStyle?: React.CSSProperties;
1515
useChromeColor?: boolean;
1616
direction?: "row" | "column";
17+
newTheme?: ReactUWP.ThemeType;
1718
}
1819

1920
export interface CodeExampleProps extends DataProps, React.HTMLAttributes<HTMLDivElement> {}
@@ -50,6 +51,7 @@ export default class CodeExample extends React.Component<CodeExampleProps, CodeE
5051
useChromeColor,
5152
direction,
5253
useSingleTheme,
54+
newTheme,
5355
...attributes
5456
} = this.props;
5557
const { theme } = this.context;
@@ -87,6 +89,7 @@ ${code}
8789
}}
8890
useSingleTheme={useSingleTheme}
8991
direction={direction}
92+
newTheme={newTheme}
9093
>
9194
{children}
9295
</DoubleThemeRender>

docs/src/components/DoubleThemeRender.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ export interface DoubleThemeRenderProps extends React.HTMLAttributes<HTMLDivElem
1010
useBorder?: boolean;
1111
useChromeColor?: boolean;
1212
useSingleTheme?: boolean;
13+
newTheme?: ReactUWP.ThemeType;
1314
}
1415

1516
export default class DoubleThemeRender extends React.Component<DoubleThemeRenderProps> {
1617
static contextTypes = { theme: PropTypes.object };
1718
context: { theme: ReactUWP.ThemeType };
1819

1920
render() {
20-
const { children, direction, themeStyle, useBorder, useChromeColor, useSingleTheme, ...attributes } = this.props;
21+
const { children, direction, themeStyle, useBorder, useChromeColor, useSingleTheme, newTheme, ...attributes } = this.props;
2122
const darkTheme = getTheme({ themeName: "dark", accent: this.context.theme.accent });
2223
const { prefixStyle } = darkTheme;
2324
const lightTheme = getTheme({ themeName: "light", accent: this.context.theme.accent });
@@ -33,7 +34,7 @@ export default class DoubleThemeRender extends React.Component<DoubleThemeRender
3334

3435
const { theme } = this.context;
3536

36-
return useSingleTheme || theme.useFluentDesign ? (
37+
return useSingleTheme || theme.useFluentDesign ? (
3738
<div
3839
style={prefixStyle({
3940
width: "100%",
@@ -43,7 +44,15 @@ export default class DoubleThemeRender extends React.Component<DoubleThemeRender
4344
justifyContent: "center"
4445
})}
4546
>
46-
{children}
47+
{newTheme ? <Theme
48+
desktopBackgroundConfig={{
49+
renderToScreen: false,
50+
enableRender: true
51+
}}
52+
theme={newTheme}
53+
>
54+
{children}
55+
</Theme> : children}
4756
</div>
4857
) : (
4958
<div

docs/src/components/Wrapper/components/Footer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function getStyles(footer: Footer): {
8989

9090
return {
9191
root: prefixStyle({
92-
...theme.acrylicTexture40.style,
92+
...theme.acrylicTexture20.style,
9393
zIndex: theme.zIndex.header,
9494
fontSize: 14,
9595
color: theme.baseHigh,

docs/src/components/Wrapper/components/Header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ function getStyles(header: Header): {
216216

217217
return {
218218
root: prefixStyle({
219-
...theme.acrylicTexture40.style,
219+
...theme.acrylicTexture20.style,
220220
fontSize: 14,
221221
color: theme.baseHigh,
222222
boxShadow: theme.isDarkTheme ? void 0 : `0 2px 8px ${theme.listLow}`,

docs/src/routes/Styles/Acrylic/SimpleExample.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export default class SimpleExample extends React.Component {
1212
fontSize: 14,
1313
fontWeight: "lighter",
1414
textAlign: "center",
15-
width: 320,
16-
height: 320,
15+
width: 200,
16+
height: 200,
1717
lineHeight: "320px",
1818
margin: 10,
1919
outline: "none",
@@ -33,14 +33,20 @@ export default class SimpleExample extends React.Component {
3333
background: theme.desktopBackground
3434
})}
3535
>
36+
<span style={{ ...itemStyle, ...theme.acrylicTexture20.style }}>
37+
theme.acrylicTexture20.style
38+
</span>
3639
<span style={{ ...itemStyle, ...theme.acrylicTexture40.style }}>
37-
theme.acrylicTexture40.background
40+
theme.acrylicTexture40.style
3841
</span>
3942
<span style={{ ...itemStyle, ...theme.acrylicTexture60.style }}>
40-
theme.acrylicTexture60.background
43+
theme.acrylicTexture60.style
4144
</span>
4245
<span style={{ ...itemStyle, ...theme.acrylicTexture80.style }}>
43-
theme.acrylicTexture80.background
46+
theme.acrylicTexture80.style
47+
</span>
48+
<span style={{ ...itemStyle, ...theme.acrylicTexture100.style }}>
49+
theme.acrylicTexture100.style
4450
</span>
4551
</div>
4652
);

docs/src/routes/Styles/Acrylic/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as readmeDoc1 from "!raw!./README1.md";
88
import * as readmeDoc2 from "!raw!./README2.md";
99
import SimpleExample from "./SimpleExample";
1010
import * as SimpleExampleCode from "!raw!./SimpleExample";
11+
import { getTheme } from "react-uwp";
1112

1213
export interface DataProps {}
1314

@@ -36,6 +37,11 @@ export default class Acrylic extends React.Component<AcrylicProps> {
3637
title="Simple Examples"
3738
code={SimpleExampleCode as any}
3839
useSingleTheme
40+
newTheme={getTheme({
41+
themeName: theme.themeName,
42+
useFluentDesign: true,
43+
desktopBackgroundImage: require("assets/images/blurBackground/viktor-jakovlev-LL4gcqlNvPU-unsplash.jpg")
44+
})}
3945
>
4046
<SimpleExample />
4147
</CodeExample>

src/Theme/index.tsx

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ export interface DataProps {
1717
/**
1818
* toogle desktopBackground show.
1919
*/
20-
enableDesktopBackground?: boolean;
20+
desktopBackgroundConfig?: {
21+
enableRender?: boolean;
22+
renderToScreen?: boolean;
23+
};
2124
/**
2225
* set theme will update callback.
2326
*/
@@ -30,11 +33,15 @@ export interface ThemeState {
3033
currTheme?: ThemeType;
3134
}
3235

36+
const desktopBgDefaultConfig = {
37+
enableRender: true,
38+
renderToScreen: true
39+
}
3340
const themeCallback: (theme?: ThemeType) => void = () => {};
3441

3542
export class Theme extends React.Component<ThemeProps, ThemeState> {
3643
static defaultProps: ThemeProps = {
37-
enableDesktopBackground: true,
44+
desktopBackgroundConfig: desktopBgDefaultConfig,
3845
themeWillUpdate: themeCallback
3946
};
4047
static childContextTypes = {
@@ -149,32 +156,32 @@ export class Theme extends React.Component<ThemeProps, ThemeState> {
149156
}
150157

151158
render() {
152-
const {
159+
let {
153160
theme,
154-
enableDesktopBackground,
161+
desktopBackgroundConfig,
155162
children,
156163
style,
157164
className,
158165
themeWillUpdate,
159166
...attributes
160167
} = this.props;
161168
const { currTheme } = this.state;
169+
desktopBackgroundConfig = desktopBackgroundConfig || desktopBgDefaultConfig;
170+
const { enableRender, renderToScreen } = desktopBackgroundConfig
162171

163172
const styles = getStyles(this);
164173
const classes = currTheme.prepareStyles({
165174
className: "theme",
166175
styles
167176
});
168177

169-
// if (this.styleEl) {
170-
// console.log("rule length: ", this.styleEl.sheet["rules"].length);
171-
// }
172-
173178
return (
174179
<div {...attributes} {...classes.root}>
175180
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/react-uwp/1.1.0/css/segoe-mdl2-assets.css" />
176181
<style type="text/css" scoped ref={styleEl => this.styleEl = styleEl} />
177-
{enableDesktopBackground && <RenderToBody {...classes.desktopBackground} />}
182+
{enableRender && (
183+
renderToScreen ? <RenderToBody {...classes.desktopBackground} /> : <div {...classes.desktopBackground} />
184+
)}
178185
<RenderToBody>
179186
<ToastWrapper
180187
toastEls={Array.from(currTheme.toasts.keys()).map(toast => toast.virtualRender())}
@@ -189,9 +196,15 @@ export class Theme extends React.Component<ThemeProps, ThemeState> {
189196

190197
function getStyles(context: Theme) {
191198
const { currTheme } = context.state;
192-
const { style } = context.props;
199+
let { style, desktopBackgroundConfig } = context.props;
200+
desktopBackgroundConfig = desktopBackgroundConfig || desktopBgDefaultConfig;
201+
const { enableRender, renderToScreen } = desktopBackgroundConfig
202+
const isInsideBg = enableRender && !renderToScreen;
203+
193204
return {
194205
root: {
206+
position: "relative",
207+
overflow: isInsideBg ? "hidden" : void 0,
195208
fontSize: 14,
196209
fontFamily: currTheme.fonts.sansSerifFonts,
197210
color: currTheme.baseHigh,
@@ -203,7 +216,7 @@ function getStyles(context: Theme) {
203216
...style
204217
} as React.CSSProperties,
205218
desktopBackground: {
206-
position: "fixed",
219+
position: isInsideBg ? "absolute" : "fixed",
207220
zIndex: -1,
208221
top: 0,
209222
left: 0,

src/styles/StyleManager.ts

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -135,30 +135,40 @@ export class StyleManager {
135135
const shouldUpdate = !this.addedCSSText[hash];
136136
if (shouldUpdate) {
137137
this.resultCSSText += CSSText;
138-
const textSize = CSSText.length;
139-
let currRule = "";
140-
let leftBraces = 0;
141138
const rules = new Map<string, boolean>();
142-
for (let i = 0; i < textSize; i ++) {
143-
const char = CSSText[i];
144-
currRule += char;
145-
if (char === "{") {
146-
leftBraces += 1;
147-
}
148-
if (char === "}") {
149-
leftBraces -= 1;
150-
if (leftBraces === 0) {
151-
this.setRules2allRules(rules, currRule);
152-
currRule = "";
153-
}
154-
}
155-
}
139+
this.cssText2rules(CSSText, currRule => {
140+
this.setRules2allRules(rules, currRule);
141+
});
156142
this.addedCSSText[hash] = { CSSText, rules };
157143
this.onAddCSSText(CSSText);
158144
this.onAddRules(rules);
159145
}
160146
}
161147

148+
cssText2rules(cssText: string, onNewReule?: (rule?: string) => void) {
149+
let currRule = "";
150+
const rules: string[] = [];
151+
let leftBraces = 0;
152+
const textSize = cssText.length;
153+
for (let i = 0; i < textSize; i ++) {
154+
const char = cssText[i];
155+
currRule += char;
156+
if (char === "{") {
157+
leftBraces += 1;
158+
}
159+
if (char === "}") {
160+
leftBraces -= 1;
161+
if (leftBraces === 0) {
162+
if (onNewReule) onNewReule(currRule);
163+
rules.push(currRule);
164+
currRule = "";
165+
}
166+
}
167+
}
168+
169+
return rules;
170+
}
171+
162172
removeCSSText = (CSSText: string) => {
163173
const hash = createHash(CSSText);
164174
delete this.addedCSSText[hash];

0 commit comments

Comments
 (0)