Skip to content

Commit 81522db

Browse files
committed
add some small tests
1 parent 17fdbaa commit 81522db

File tree

14 files changed

+206
-22
lines changed

14 files changed

+206
-22
lines changed

Assets/Scenes/UIToolkit.unity

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ MonoBehaviour:
163163
SourceText:
164164
ResourcesPath:
165165
UseDevServer: 1
166-
DevServer: http://localhost:3100
166+
DevServer: http://localhost:3100/uitoolkit.js
167167
EngineType: 0
168168
Globals:
169169
Entries: []

Assets/Scripts/InteropTest.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using ReactUnity.Helpers;
23
using ReactUnity.UGUI;
34
using UnityEngine;
45
using UnityEngine.InputSystem;
@@ -8,19 +9,11 @@ namespace MyInterop
89
{
910
public class InteropTest : MonoBehaviour
1011
{
11-
public event Action<string> OnKeyPress;
12+
public ReactAction<string> OnKeyPress = new ReactAction<string>();
1213
IDisposable dispose;
1314

14-
public Action AddKeyPressListener(object callback)
15-
{
16-
var cb = ReactUnity.Helpers.Callback.From(callback);
17-
Action<string> listener = (val) => cb.Call(val);
18-
19-
OnKeyPress += listener;
20-
21-
return () => OnKeyPress -= listener;
22-
}
23-
15+
[Obsolete]
16+
public Action AddKeyPressListener(object callback) => OnKeyPress.AddListener(callback);
2417

2518
void OnEnable()
2619
{

react/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@
1919
"@emotion/react": "^11.10.6",
2020
"@emotion/styled": "^11.10.6",
2121
"@reactunity/material": "^0.15.0",
22-
"@reactunity/renderer": "^0.15.0",
23-
"@reduxjs/toolkit": "^1.9.2",
24-
"axios": "^1.3.3",
22+
"@reactunity/renderer": "^0.15.2",
23+
"@reduxjs/toolkit": "^1.9.3",
24+
"axios": "^1.3.4",
2525
"bootstrap": "^5.2.3",
2626
"clsx": "^1.2.1",
2727
"history": "^5.3.0",
2828
"react": "^18.2.0",
2929
"react-bootstrap": "^2.7.2",
30-
"react-icons": "^4.7.1",
30+
"react-icons": "^4.8.0",
3131
"react-jss": "^10.10.0",
3232
"react-redux": "^8.0.5",
33-
"react-router": "^6.8.1",
33+
"react-router": "^6.9.0",
3434
"react-unity-webgl": "^9.4.0",
3535
"redux": "^4.2.1",
3636
"redux-persist": "^6.0.0",
37-
"styled-components": "^5.3.6",
37+
"styled-components": "^5.3.9",
3838
"twin.macro": "^3.1.0"
3939
},
4040
"devDependencies": {
@@ -43,7 +43,7 @@
4343
"@types/react-redux": "^7.1.25",
4444
"babel-plugin-twin": "^1.1.0",
4545
"tailwindcss": "^3.2.7",
46-
"typescript": "^4.9.5"
46+
"typescript": "^5.0.2"
4747
},
4848
"babelMacros": {
4949
"twin": {

react/src/entry/uitoolkit.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
import '../uitoolkit';
1+
import '../uitoolkit/home';

react/src/pages/style-frameworks/tailwind/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import './index.css';
22

33
export function TailwindPage() {
44
return <div className={'tailwind-root flex-row'}>
5-
65
<div className={'flex-row'}>
76
<button className={'bg-blue-400 hover:bg-red-400 p-3 m-3 transition-colors hover:translate-y-1'}>
87
Tailwind Button

react/src/pages/todo/index.css

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
background-color: #dedede;
99
border-radius: 8px;
1010
box-shadow: 1px 1px 6px -2px black;
11+
12+
--item-animation-duration: 400ms;
1113
}
1214

1315
.todo-header {
@@ -44,7 +46,11 @@
4446
border: 1px solid #dedede;
4547
border-radius: 8px;
4648

47-
--item-animation-duration: 400ms;
49+
/* --item-animation-duration: 400ms; */
50+
}
51+
52+
.todo-item:before {
53+
content: var(--item-animation-duration);
4854
}
4955

5056
.todo-item:not(:first-child) {

react/src/tests/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### What is this folder?
2+
3+
This folder contains quick reproductions for testing some bug reports by users. You can delete this report safely.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { render } from "@reactunity/renderer";
2+
import React, { useState } from "react";
3+
4+
function ErrorChild2() {
5+
const [state, setState] = useState(null);
6+
7+
return <div class="error-child-2">
8+
{state.value}
9+
</div>;
10+
}
11+
12+
function ErrorChild1() {
13+
return <div class="error-child-1">
14+
<ErrorChild2 />
15+
</div>;
16+
}
17+
18+
export default function ErrorTest() {
19+
20+
return (
21+
<ErrorChild1 />
22+
);
23+
}
24+
25+
26+
const createdRefs = new Set();
27+
28+
function createRef(ref) {
29+
if (ref && !createdRefs.has(ref)) {
30+
createdRefs.add(ref);
31+
console.log("Created ref", ref);
32+
}
33+
}
34+
35+
export class ErrorBoundary extends React.Component<any, any> {
36+
constructor(props) {
37+
super(props);
38+
this.state = { hasError: false, error: null };
39+
}
40+
41+
static getDerivedStateFromError(error) {
42+
// Update state so the next render will show the fallback UI.
43+
return { hasError: true, error };
44+
}
45+
46+
render() {
47+
if (this.state.hasError) {
48+
return <view ref={createRef}
49+
id='__react-unity-error-boundary'
50+
style={{ color: 'crimson', padding: 20, fontSize: 16 }}>
51+
<view style={{ marginBottom: '12px' }}>
52+
{this.state.error?.message || ''}
53+
</view>
54+
<view>{this.state.error?.stack || ''}</view>
55+
</view>;
56+
}
57+
58+
return this.props.children;
59+
}
60+
}
61+
62+
render(
63+
<ErrorBoundary>
64+
<ErrorTest />
65+
</ErrorBoundary>, { disableHelpers: true });
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* @tailwind base; */
2+
@tailwind components;
3+
@tailwind utilities;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { render } from "@reactunity/renderer";
2+
import { useMemo, useState } from "react";
3+
import './index.css';
4+
5+
const ROWS = 125;
6+
const COLUMNS = 15;
7+
8+
function Row({ row, columns }: { row: number; columns: number }) {
9+
const children = useMemo(() => {
10+
return Array(columns)
11+
.fill(0)
12+
.map((_, col) => {
13+
return (
14+
<div key={col} class={`mr-1 h-6 w-[70px] bg-green-300`} id={`cell-${row}-${col}`}
15+
onClick={() => console.log(`Clicked ${row} x ${col}`)}>
16+
{`${row} x ${col}`}
17+
</div>
18+
);
19+
});
20+
}, [columns, row]);
21+
22+
return <div class="mb-1 flex flex-row" id={`row-${row}`}>{children}</div>;
23+
}
24+
25+
function Rows({ columns, rows }: { columns: number; rows: number }) {
26+
const children = useMemo(() => {
27+
return Array(rows)
28+
.fill(0)
29+
.map((_, i) => {
30+
return <Row key={i} row={i} columns={columns} />;
31+
});
32+
}, [columns, rows]);
33+
34+
return <div class="flex flex-col p-3">{children}</div>;
35+
}
36+
37+
export default function StressTest() {
38+
const [rows, setRows] = useState(ROWS);
39+
const [columns, setColumns] = useState(COLUMNS);
40+
41+
return (
42+
<scroll>
43+
<button
44+
class="p-2 bg-white rounded-md w-[200px]"
45+
onClick={() => {
46+
const newRows = Math.floor(Math.random() * ROWS);
47+
const newColumns = Math.floor(Math.random() * COLUMNS);
48+
49+
setRows(newRows);
50+
setColumns(newColumns);
51+
}}
52+
>
53+
Reroll
54+
</button>
55+
<Rows key={rows} columns={columns} rows={rows} />
56+
</scroll>
57+
);
58+
}
59+
60+
render(<StressTest />);

0 commit comments

Comments
 (0)