Skip to content

Commit 6ab47c7

Browse files
committed
add value based custom component example
1 parent bc96460 commit 6ab47c7

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

Assets/Scripts/ExampleCustomComponent/CustomComponentInitializer.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using ReactUnity;
2-
using System.Collections;
3-
using System.Collections.Generic;
42
using UnityEngine;
53

64
public class CustomComponentInitializer : MonoBehaviour

Assets/Scripts/ExampleCustomComponent/custom-component-react.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19164,9 +19164,11 @@ var custom_component_App = /** @class */ (function (_super) {
1916419164
return _this;
1916519165
}
1916619166
App.prototype.render = function () {
19167+
var ElementName = 'customButton';
1916719168
return (Object(react.createElement)("view", { layout: { Height: '100%', AlignItems: 'Center', JustifyContent: 'Center' } },
1916819169
Object(react.createElement)("button", { layout: { MarginBottom: 20 }, style: { fontColor: 'white' } }, "Normal Button"),
19169-
Object(react.createElement)("customButton", { style: { fontColor: 'white' } }, "Custom Button")));
19170+
Object(react.createElement)("customButton", { layout: { MarginBottom: 20 }, style: { fontColor: 'white' } }, "Custom Button"),
19171+
Object(react.createElement)(ElementName, { style: { fontColor: 'white' } }, "Custom Button - Value Based")));
1917019172
};
1917119173
return App;
1917219174
}(react.Component));

react/src/custom-component/index.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from 'react';
22
import { ReactUnity, Button, NativeInstance } from 'react-unity-renderer';
33

44

5+
// Add strong typing for customButton component
56
declare module 'React' {
67
namespace JSX {
78
interface IntrinsicElements {
@@ -10,24 +11,32 @@ declare module 'React' {
1011
}
1112
}
1213

14+
1315
class App extends React.Component<{}, {}> {
1416
onInputChange = (val: string) => {
1517
NamedAssets.CubeMove["Speed"] = parseFloat(val) || 0;
1618
};
1719

1820
render() {
21+
const ElementName: string = 'customButton';
22+
1923
return (
20-
<view
21-
layout={{ Height: '100%', AlignItems: 'Center', JustifyContent: 'Center' }}>
24+
<view layout={{ Height: '100%', AlignItems: 'Center', JustifyContent: 'Center' }}>
2225

2326
<button layout={{ MarginBottom: 20 }} style={{ fontColor: 'white' }}>
2427
Normal Button
2528
</button>
2629

27-
<customButton style={{ fontColor: 'white' }}>
30+
{/* Recommended - Strong typed */}
31+
<customButton layout={{ MarginBottom: 20 }} style={{ fontColor: 'white' }}>
2832
Custom Button
2933
</customButton>
3034

35+
{/* Not Recommended - Not strong typed */}
36+
<ElementName style={{ fontColor: 'white' }}>
37+
Custom Button - Value Based
38+
</ElementName>
39+
3140
</view>
3241
);
3342
}

0 commit comments

Comments
 (0)