Git Product home page Git Product logo

react-vr-with-awareness's Introduction

react-vr-with-awareness

๐Ÿ‘€ HOC for creating aware components in ReactVR

Usage

import React from "react";
import { AppRegistry, Text, View } from "react-vr";

// import
const Aware, {withAwareness} = require("react-vr-with-awareness");

// create a component with HOC
const AwareFromHOC = withAwareness(beingLookedAt => (
  <Text
    style={{
      backgroundColor: "#777879",
      fontSize: 0.8,
      fontWeight: "400",
      layoutOrigin: [0.5, 0.5],
      paddingLeft: 0.2,
      paddingRight: 0.2,
      textAlign: "center",
      textAlignVertical: "center",
      transform: [{ translate: [0, 0, -3] }]
    }}
  >
    {beingLookedAt ? "Hi there!" : "Look at me!"}
  </Text>
));

// or use the supplied component `Aware` with render props
export default class example extends React.Component {
  render() {
    return (
      <View>
        {/* Aware component from HOC */}
        <AwareFromHOC />
        
        {/* Aware component with render props */}
        <Aware render={seen => (
          <Text
              style={{
                backgroundColor: "#777879",
                fontSize: 0.8,
                fontWeight: "400",
                layoutOrigin: [0.5, 0.5],
                paddingLeft: 0.2,
                paddingRight: 0.2,
                textAlign: "center",
                textAlignVertical: "center",
                transform: [{ translate: [0, 2, -3] }]
              }}
            >
              {seen ? "seen" : "not seen"}
            </Text>
        )}/>
      </View>
    );
  }
}

AppRegistry.registerComponent("example", () => example);

Docs

Aware component takes a render props which is a function with 1 boolean parameter which indicates if the component is being seen or not. The function should return a react component. This function is similar from the one used in the HOC.

License

MIT. See LICENSE

react-vr-with-awareness's People

Contributors

mathdroid avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

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.