{"id":20416398,"url":"https://github.com/folkloreinc/react-scene","last_synced_at":"2025-10-25T23:05:18.968Z","repository":{"id":57344040,"uuid":"67806551","full_name":"folkloreinc/react-scene","owner":"folkloreinc","description":"React Component that helps to handle a scene lifecycle (play, pause, mute, unmute, resize...).","archived":false,"fork":false,"pushed_at":"2017-02-10T16:41:09.000Z","size":284,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-02T21:06:19.278Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/folkloreinc.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-09T14:38:34.000Z","updated_at":"2022-09-12T03:02:25.000Z","dependencies_parsed_at":"2022-09-12T06:50:56.555Z","dependency_job_id":null,"html_url":"https://github.com/folkloreinc/react-scene","commit_stats":null,"previous_names":["folkloreatelier/react-scene"],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/folkloreinc%2Freact-scene","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/folkloreinc%2Freact-scene/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/folkloreinc%2Freact-scene/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/folkloreinc%2Freact-scene/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/folkloreinc","download_url":"https://codeload.github.com/folkloreinc/react-scene/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241570907,"owners_count":19984002,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T06:19:44.132Z","updated_at":"2025-10-25T23:05:18.900Z","avatar_url":"https://github.com/folkloreinc.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"React Scene\n============\n\n## Installation\n```\nnpm install --save react-scene\n```\n\n## Usage\n\nReact Scene is a component that expose different methods to handle a typic scene logic.\n\nThe methods are:\n- `load` Load everything that has to be loaded\n- `build` Build the scene (if you need to create or rend any object)\n- `resize` Resize the scene. It is also automatically called when the `width` or `height` props change on the scene\n- `mute` To mute the scene\n- `unmute` To unmute the scene\n- `play` Play the scene\n- `pause` Pause the scene\n- `end` End the scene\n- `destroy` Destroy any resources\n\nEach method can be synchronous or asynchronous and will trigger lifecycle methods on the parent listening to them. Those lifecycles methods are in the following format `sceneWill[Method]` and `sceneDid[Method]` (Ex: `sceneWillLoad`, `sceneDidLoad`)\n\n### Basic usage\n\n##### Creating a scene component\n\n```js\n\nvar React = require('react');\nvar ReactScene = require('react-scene');\nvar createjs = require('preload-js');\n\nvar Scene = React.createClass({\n    \n    render: function()\n    {\n        return (\n            \u003cdiv\u003e\n                \n            \u003c/div\u003e\n        );\n    },\n    \n    /**\n     * Scene methods\n     */\n    load: function(e)\n    {\n        // Methods can be asynchronous by either calling the async method\n        // on the first argument. The async method returns a function\n        // that needs to be called when the action is done. Or you can\n        // also return a promise and it will automatically wait for the\n        // promise completion before calling sceneDidLoad\n        var done = e.async();\n        \n        this.preloadQueue = new createjs.LoadQueue();\n        this.preloadQueue.addEventListener('complete', done);\n        this.preloadQueue.loadFile({\n            id: 'photo',\n            src: '/photo.jpg'\n        });\n    },\n    \n    build: function(e)\n    {\n        \n    },\n    \n    resize: function(e)\n    {\n        \n    },\n    \n    mute: function(e)\n    {\n        \n    },\n    \n    unmute: function(e)\n    {\n        \n    },\n    \n    play: function(e)\n    {\n        var that = this;\n        setTimeout(function()\n        {\n            // If you need to control a scene within a scene. There is a scene\n            // props containing the scene methods. Calling the `end` when the\n            // playback is done is a good example.\n            \n            that.props.scene.end();\n        }, 2000);\n    },\n    \n    pause: function(e)\n    {\n        \n    },\n    \n    end: function(e)\n    {\n        \n    },\n    \n    destroy: function(e)\n    {\n        \n    }\n    \n});\n\n// Calling createScene with the Component as the first argument, will wrap\n// your scene component in a ReactScene Component and assure that the methods\n// you define will be called and the corresponding lifecycle methods.\nmodule.exports = ReactScene.createScene(Scene);\n\n```\n\n##### Using the scene component\n\n```js\n\nvar React = require('react');\nvar Scene = require('./Scene');\n\nvar Story = React.createClass({\n    \n    render: function()\n    {\n        return (\n            \u003cdiv\u003e\n                \u003cScene\n                    sceneWillLoad={this.onSceneWillLoad}\n                    sceneDidLoad={this.onSceneDidLoad}\n                    sceneWillPlay={this.onSceneWillPlay}\n                    sceneDidPlay={this.onSceneDidPlay}\n                    /\u003e\n            \u003c/div\u003e\n        );\n    },\n    \n    onSceneWillLoad: function()\n    {\n        console.log('Scene will load');\n    },\n    \n    onSceneDidLoad: function()\n    {\n        console.log('Scene did load');\n    },\n    \n    onSceneWillPlay: function()\n    {\n        console.log('Scene will play');\n    },\n    \n    onSceneDidPlay: function()\n    {\n        console.log('Scene did play');\n    }\n    \n});\n\nmodule.exports = Story;\n\n```\n\n##### Controlling the scene\n\n```js\n\nvar React = require('react');\nvar Scene = require('./Scene');\n\nvar Story = React.createClass({\n    \n    getInitialState: function()\n    {\n        return {\n            remote: null\n        };\n    },\n    \n    render: function()\n    {\n        return (\n            \u003cdiv\u003e\n                \u003cdiv\u003e\n                    \u003cbutton type=\"button\" onClick={this.onClickPlay}\u003ePlay\u003c/button\u003e\n                \u003c/div\u003e\n                \u003cScene\n                    ref=\"scene\"\n                    onRemote={this.onRemote}\n                    sceneWillLoad={this.onSceneWillLoad}\n                    sceneDidLoad={this.onSceneDidLoad}\n                    sceneWillPlay={this.onSceneWillPlay}\n                    sceneDidPlay={this.onSceneDidPlay}\n                    sceneWillEnd={this.onSceneWillEnd}\n                    sceneDidEnd={this.onSceneDidEnd}\n                    /\u003e\n            \u003c/div\u003e\n        );\n    },\n    \n    onClickPlay: function(e)\n    {\n        e.preventDefault();\n        \n        // Scene methods can be called either by using a `ref` \n        this.refs.scene.play();\n        \n        // or using the remote provided by the `onRemote`\n        this.state.remote.play();\n    },\n    \n    onRemote: function(remote)\n    {\n        // When providing an onRemote props to a scene, the function\n        // is called with a remote object as the first argument. This\n        // object has every scene methods. It can be stored in the state\n        // for later use.\n        this.setState({\n            remote: remote\n        });\n    },\n    \n    onSceneWillLoad: function()\n    {\n        console.log('Scene will load');\n    },\n    \n    onSceneDidLoad: function()\n    {\n        console.log('Scene did load');\n    },\n    \n    onSceneWillPlay: function()\n    {\n        console.log('Scene will play');\n    },\n    \n    onSceneDidPlay: function()\n    {\n        console.log('Scene did play');\n    },\n    \n    onSceneWillEnd: function()\n    {\n        console.log('Scene will end');\n    },\n    \n    onSceneDidEnd: function()\n    {\n        console.log('Scene did end');\n    }\n    \n});\n\nmodule.exports = Story;\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffolkloreinc%2Freact-scene","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffolkloreinc%2Freact-scene","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffolkloreinc%2Freact-scene/lists"}