Skip to content
This repository was archived by the owner on Feb 12, 2023. It is now read-only.

Commit c8eeaf9

Browse files
committed
Add more styles
1 parent caab00a commit c8eeaf9

File tree

5 files changed

+92
-1
lines changed

5 files changed

+92
-1
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import React from 'react';
2+
import Panel from './panel';
3+
4+
const backdropStyles = {
5+
position: 'absolute',
6+
left: 0,
7+
top: 0,
8+
width: '100%',
9+
height: '100%',
10+
backgroundColor: '#000000aa',
11+
justifyContent: 'center'
12+
}
13+
14+
const panelOuterStyle = {
15+
width: 400,
16+
height: 300,
17+
alignSelf: 'center',
18+
verticalAlign: 'center'
19+
}
20+
21+
const panelInnerStyle = {
22+
flexDirection: 'row'
23+
}
24+
25+
const buttonStyle = {
26+
alignSelf: 'flex-end',
27+
width: 100,
28+
marginBottom: 15,
29+
marginLeft: 15
30+
};
31+
32+
export default function Popup({ onClose }) {
33+
34+
return <element style={backdropStyles}>
35+
<Panel outerStyle={panelOuterStyle} innerStyle={panelInnerStyle}>
36+
<button style={buttonStyle} onClick={onClose} text="Close" />
37+
</Panel>
38+
</element>
39+
}

examples/Assets/Resources/components/popup.jsx.meta

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/Assets/Resources/index.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import React from 'react';
1+
import React, { useState } from 'react';
22
import { render } from 'unity-renderer';
33
import TabPanel from './components/tab-panel';
44
import Counter from './components/counter';
55
import ComponentPreview from './components/component-preview';
66
import Todo from './components/Todo';
7+
import Popup from './components/popup';
78

89
const margin = (margin) => ({
910
marginTop: margin,
@@ -28,6 +29,8 @@ const Tab1Style = Object.assign(margin('auto'), {
2829
});
2930

3031
function App() {
32+
const [popupOpened, setPopupOpened] = useState(false);
33+
3134
return (
3235
<element style={rootStyle}>
3336
<TabPanel style={tabPanelStyle}>
@@ -49,7 +52,11 @@ function App() {
4952
<TabPanel.Panel name="ECS TODO example">
5053
<Todo />
5154
</TabPanel.Panel>
55+
<TabPanel.Panel name="Popup example">
56+
<button onClick={() => setPopupOpened(true)} text="Open popup" />
57+
</TabPanel.Panel>
5258
</TabPanel>
59+
{popupOpened && <Popup onClose={() => setPopupOpened(false)} />}
5360
</element>
5461
);
5562
}

packages/com.mkmarek.uielements.react/Runtime/Bridge/JsToNativeBridgePayload.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ public class ComponentStyle
104104
public string minHeight;
105105
public string maxWidth;
106106
public string maxHeight;
107+
public string position;
108+
public string top;
109+
public string bottom;
110+
public string left;
111+
public string right;
107112
}
108113
}
109114
}

packages/com.mkmarek.uielements.react/Runtime/Bridge/Styles/StyleMapper.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,21 @@ public static void AssignStyleProps(JsToNativeBridgePayload.BridgeMessage.Compon
110110

111111
if (!string.IsNullOrWhiteSpace(style.unityTextAlign))
112112
element.style.unityTextAlign = ParseTextAlign(style.unityTextAlign);
113+
114+
if (!string.IsNullOrWhiteSpace(style.position))
115+
element.style.position = ParsePositionStyleEnum(style.position);
116+
117+
if (!string.IsNullOrWhiteSpace(style.top))
118+
element.style.top = ParseStyleLength(style.top);
119+
120+
if (!string.IsNullOrWhiteSpace(style.bottom))
121+
element.style.bottom = ParseStyleLength(style.bottom);
122+
123+
if (!string.IsNullOrWhiteSpace(style.left))
124+
element.style.left = ParseStyleLength(style.left);
125+
126+
if (!string.IsNullOrWhiteSpace(style.right))
127+
element.style.right = ParseStyleLength(style.right);
113128
}
114129

115130
public static Color ParseColor(string hexColor)
@@ -201,6 +216,21 @@ private static StyleEnum<Justify> ParseJustifyStyleEnum(string styleJustifyConte
201216
return default;
202217
}
203218

219+
private static StyleEnum<Position> ParsePositionStyleEnum(string position)
220+
{
221+
var keyword = GetStyleKeyword(position);
222+
223+
if (keyword.HasValue) return new StyleEnum<Position>(keyword.Value);
224+
225+
switch (position)
226+
{
227+
case "relative": return new StyleEnum<Position>(Position.Relative);
228+
case "absolute": return new StyleEnum<Position>(Position.Absolute);
229+
}
230+
231+
return default;
232+
}
233+
204234
private static StyleEnum<FlexDirection> ParseFlexDirectionStyleEnum(string styleFlexDirection)
205235
{
206236
var keyword = GetStyleKeyword(styleFlexDirection);

0 commit comments

Comments
 (0)