Git Product home page Git Product logo

react-yue's Introduction

react-yue

npm-version build-badge

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 and react-yue-app as examples of using this lib.

mac

Get Started

Use node v8 or v9 as they are supported by the builds of gui.

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)
}

Style / Layout

Yue use yoga layout and you can use these properties in the style property. It's also possible to provide other styles via the style prop.

  • color: hex|rgb|rgba|hsl|hsla|name of a color
  • backgroundColor: hex|rgb|rgba|hsl|hsla| name of a color
  • fontSize: number representing a pixel value
  • fontWeight: supports 100-900 and all values in https://libyue.com/docs/latest/js/api/font_weight.html
  • fontFamily: name of a font to use
  • fontStyle: normal|italic
  • textAlign: left|center|right
  • verticalAlign: top|middle|bottom
import React from 'react'

export default function MyComp() {
  return (
    <container
      style={{
        flex: 1,
        flexDirection: 'row',
        backgroundColor: 'black'
      }}
    >
      <container
        style={{
          justifyContent: 'center',
        }}
      >
        <label
          text="hello"
          style={{
            color: 'white',
            fontSize: 14
          }}
        />
      </container>
    </container>
  )
}

Components

Below are what components and their props you can use with react-yue. For more details, please check the official document.

View (base class)

props:

  • Boolean visible
  • Boolean enabled
  • Boolean focusable
  • Boolean mouseDownCanMoveWindow

events:

  • onMouseDown
    • params
      • View self
  • onMouseUp
    • params
      • View self
      • MouseEvent event
  • onMouseMove
    • params
      • View self
      • MouseEvent event
  • onMouseEnter
    • params
      • View self
      • MouseEvent event
  • onMouseLeave
    • params
      • View self
      • MouseEvent event
  • onKeyDown
    • params
      • View self
      • KeyEvent event
  • onKeyUp
    • params
      • View self
      • KeyEvent event
  • onSizeChanged
    • params
      • View self
      • KeyEvent event
  • onCaptureLost
    • params
      • View self
      • KeyEvent event

Button

props:

  • Button::Type type
  • Boolean defaultChecked
  • String title
  • Image image

events:

  • onClick(self)
    • params
      • Button self

Container

events:

  • onDraw(self, painter, painter)
    • params
      • Container self
      • Painter painter - The drawing context of the view.
      • RectF dirty - The area in the view to draw on.

Entry

props:

  • Entry::Type type
  • String text

events:

  • onTextChange(self)
    • params
      • Entry self
  • onActivate(self)
    • params
      • Entry self

Group

props:

  • String title
  • View children

Label

props:

  • String text

ProgressBar

props:

  • Number percent
  • Boolean indeterminate

Scroll

props:

  • Scroll::Policy hpolicy
  • Scroll::Policy vpolicy
  • Boolean overlayScrollbar
  • SizeF size contentSize
  • View children

TextEdit

props:

  • String text
  • Scroll::Policy hpolicy
  • Scroll::Policy vpolicy
  • Boolean overlayScrollbar

events:

  • onTextChange(self)
    • params
      • TextEdit self

Vibrant

props:

  • Vibrant::Material material
  • Vibrant::BlendingMode mode

Using with yackage

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.

Run Tests

npm run test

react-yue's People

Contributors

kuba-orlik avatar oyyd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-yue's Issues

Match react native API

Hi,

Would you be interested in a PR matching react native's API where possible?

Off the top of my head it would be:

  • container -> View
  • scroll -> ScrollView
  • label -> Text
  • entry/textedit -> TextInput

with certain props remapped, eg:

<label text="hey" />

would be:

<text>hey</text>

Is that aligned with where you want to take this library?

Thanks!
Darío

Window disappears when requiring a lib with a large dependency

I've been encountering random "soft crashes" of my simple react-yue app. The app started to crash once I added require("jsdom") to it. I assumed that something in jsdom interferes with node-gui and spent more than 3 days looking for a cause. Eventually I realized it's not the content of the required dependency, but its size.

How to reproduce

I'll use react-yue-app as the simplest example.

After cloning the repo, running the app as it is works just fine.

Then let's generate a large JSON file:

seq 20000000 | awk 'BEGIN {print "["} {print $0 ","} END {print "\"end\"]"}' > numbers-large.json

and then add

require("./numbers-large.js");

to the app code.

Now the app runs, but no window appears. Putting require("./numbers-large.js"); in a setTimeout causes the window to appear, and then disappear after a short amount of time.

The app doesn't crash. The window just disappears.

EDIT: on some occasions the window doesn't disappear immediately, but after around 8 seconds.

Supported react versions

Hi! I looked into the package.json file and I see that the supported react versions are anything above 16.2.0, is that correct?

Build instructions

I've tried building the lib with npm run build, but linking to it locally gives errors like:

(node:24207): GLib-GObject-WARNING **: 14:21:38.601: cannot register existing type 'NUContainer'

(node:24207): GLib-GObject-WARNING **: 14:21:38.601: cannot add private field to invalid (non-instantiatable) type '<invalid>'

(node:24207): GLib-CRITICAL **: 14:21:38.601: g_once_init_leave: assertion 'result != 0' failed

(node:24207): GLib-GObject-CRITICAL **: 14:21:38.602: g_object_new_with_properties: assertion 'G_TYPE_IS_OBJECT (object_type)' failed

Are there some more build steps to achieve a working version that I can locally link to?

Usage?

Hey, I just found this project, any tips on how to get started?

Log warnings for unsupported styles

Currently only a subset of style attributes are supported in the style prop. It would be good to warn users when they attempt to use a style attribute that we do not support yet.

Changes in state not reflected in the component

I'm trying to test a simple state-changing case, but the UI doesn't reflect the state. Here's the code:

const React = require("react");
const gui = require("gui");
const { render } = require("react-yue");

// Create your react component:
class App extends React.Component {
	constructor() {
		super();
		this.state = {
			text: "loading",
		};
	}
	componentDidMount() {
		this.setState({ text: "it works" });
	}
	render() {
		console.log("render!", this.state.text);
		return React.createElement(
			"container",
			{
				style: {
					flexDirection: "row",
					flex: 1,
					justifyContent: "center",
				},
			},
			React.createElement("label", {
				text: this.state.text,
			})
		);
	}
}

// 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);
}

It creates a window, but it only says "loading", and never changes to "it works!" -- even though the log output says:

render! loading
render! it works

It happens both with node and with yode.

Am I doing something wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.