The view of OvenPlayer has consisted of a template that extended OvenTemplate.
The template has a minimal life cycle starting with onRendered() and ending with onDestroyed(), and you can set an event callback with a valid scope in the template.
The top-level parent template is view/view.js. View creates child Controls and Helpers templates. Also, Controls and Helpers create and control child templates, respectively.
Through our example TextView (view/example/textview.js), we will explain in the following part how child templates are created, controlled, and passed data by the parent template.
Register a template
The OvenPlayer template has a pair of controller and view, each named {templateName}.js and {templateName}Template.js.
You need to register view separately in Templates.
We have configured textviewTemplate.js corresponding to the view in the TextView. So you register textviewTemplate.js in view/engine/Templates.js.
view/engine/Templates.js
import TextViewTemplate from 'view/example/textviewTemplate';
import ViewTemplate from 'view/viewTemplate';
import HelpersTemplate from 'view/components/helpers/mainTemplate';
...
const Templates = {
TextViewTemplate,
ViewTemplate,
HelpersTemplate,
BigButtonTemplate,
...
};
export default Templates;
Use a template
In this part, we will show you how to create the TextView in helpers/main.js, the top-level parent of Helpers.
You import textview.js which is controller in the TextView.
view/components/helpers/main.js
import OvenTemplate from "view/engine/OvenTemplate";
import BigButton from "view/components/helpers/bigButton";
import MessageBox from "view/components/helpers/messageBox";
import CaptionViewer from "view/components/helpers/captionViewer";
import Spinner from "view/components/helpers/spinner";
//It adds a textview template for testing.
import TextView from 'view/example/textview';
...
const Helpers = function($container){
let bigButton = "", messageBox = "", captionViewer = "", spinner = "", textView;
...
const onRendered = function($current, template){
//It creates the TextView right after Helper is loaded on the screen.
textView = TextView($current, api, "Hello world. Nice to meet you.");
...
});
//Callback that is called when Helpers are removed in OvenPlayer.
const onDestroyed = function(template){
textView.destroy(); //When Helpers, which is the parent template, is removed, the textView is also removed.
api.off(READY, null, template);
api.off(PLAYER_STATE, null, template);
...
};
//The event to be used by Helpers. However, Helpers are used as a container for the template, so there are no special events.
const events = {
};
return OvenTemplate($container, "Helpers", null, events, onRendered, onDestroyed );
};
export default Helpers;