This is a lib to help you render the View of Yue in the react way.
Moreover, it's possible to utilize react-yue to a hot reload developing experience.
You may want to check do-space-client as an example of using this lib.
mac |
---|
npm i react-yue react gui
Render your view into a container:
import React from 'react'
import gui from 'gui'
import { render } from 'react-yue'
// Create your react component:
function App() {
return (
<container
style={{
flexDirection: 'row',
flex: 1,
justifyContent: 'center',
}}
>
<label
text="hello"
/>
</container>
)
}
// Create a window and a root container:
const win = gui.Window.create({})
win.setContentSize({ width: 400, height: 250 })
const contentView = gui.Container.create()
contentView.setStyle({ flexDirection: 'row' })
win.setContentView(contentView)
win.center()
win.activate()
// Create your react elements and render them:
render(<App />, contentView)
// Start your app
if (!process.versions.yode) {
gui.MessageLoop.run()
process.exit(0)
}
Check this ES5 example if you want to run it without any code transforming:
const React = require('react')
const gui = require('gui')
const { render } = require('react-yue')
// Create your react component:
function App() {
return React.createElement('container', {
style: {
flexDirection: 'row',
flex: 1,
justifyContent: 'center',
},
}, React.createElement('label', {
text: 'hello',
}))
}
// Create a window and a root container:
const win = gui.Window.create({})
win.setContentSize({ width: 400, height: 250 })
const contentView = gui.Container.create()
contentView.setStyle({ flexDirection: 'row' })
win.setContentView(contentView)
win.center()
win.activate()
// Create your react elements and render them:
render(React.createElement(App), contentView)
// Start your app
if (!process.versions.yode) {
gui.MessageLoop.run()
process.exit(0)
}
Yue use yoga layout and you can use these properties in the style
property:
import React from 'react'
export default function MyComp() {
return (
<container
style={{
flex: 1,
flexDirection: 'row',
}}
>
<container
style={{
justifyContent: 'center',
}}
>
<label text="hello" />
</container>
</container>
)
}
Below are what components and their props you can use with react-yue. For more details, please check the official document.
props:
Boolean
visibleBoolean
enabledBoolean
focusableBoolean
mouseDownCanMoveWindowFont
fontColor
colorColor
backgroundColor
events:
- onMouseDown
- params
View
self
- params
- onMouseUp
- params
View
selfMouseEvent
event
- params
- onMouseMove
- params
View
selfMouseEvent
event
- params
- onMouseEnter
- params
View
selfMouseEvent
event
- params
- onMouseLeave
- params
View
selfMouseEvent
event
- params
- onKeyDown
- params
View
selfKeyEvent
event
- params
- onKeyUp
- params
View
selfKeyEvent
event
- params
- onSizeChanged
- params
View
selfKeyEvent
event
- params
- onCaptureLost
- params
View
selfKeyEvent
event
- params
props:
Button::Type
typeBoolean
defaultCheckedString
titleImage
image
events:
- onClick(self)
- params
Button
self
- params
events:
- onDraw(self, painter, painter)
- params
Container
selfPainter
painter - The drawing context of the view.RectF
dirty - The area in the view to draw on.
- params
props:
Entry::Type
typeString
text
events:
- onTextChange(self)
- params
Entry
self
- params
- onActivate(self)
- params
Entry
self
- params
props:
String
titleView
children
props:
String
text
props:
Number
percentBoolean
indeterminate
props:
Scroll::Policy
hpolicyScroll::Policy
vpolicyBoolean
overlayScrollbarSizeF size
contentSizeView
children
props:
String
textScroll::Policy
hpolicyScroll::Policy
vpolicyBoolean
overlayScrollbar
events:
- onTextChange(self)
- params
TextEdit
self
- params
props:
Vibrant::Material
materialVibrant::BlendingMode
mode
React will require
its modules dynamically so that you can't correctly package your apps when using yackage to package your Node.js project into an executable.
As yackage doesn't support customized code transforming, webpack is recommended to bundle your js correctly. You can take the config of do-space-client as a reference.
npm run test