UNPKG

drnaf

Version:

Dynamic React-Native Application Framework

134 lines (101 loc) 3.27 kB
import React, { Component } from 'react' import { View, Image, Text, TouchableHighlight } from 'react-native' // import { Fire, DRNAFButton, } from 'drnaf' import { post } from './networks/Fire' import { DRNAFComponent } from './inherites/DRNAFComponent'; import { DRNAFView } from './DRNAFView'; import { l } from './utilities/Logs' export class DRNAFLauncher extends DRNAFComponent { constructor(props) { super(props, 'DRNAFLauncher') this.state = { drnaf_configs: props.drnaf_configs, application_id: props.application_id, page: null, navigation: props.navigation, } } /** Feature methods */ receiveCallback(str) { alert('received callback') } /** API methods */ apiGetPageSet() { // prepare usage variables const mtn = this.ct + "apiGetPageSet() "; const request = { "work": "GET_LAUNCHER_PAGE", "application_id": this.state.application_id } const jck = (val) => { // failed condition if (!val.status) { // alert alert(' failed during try to connect to API. ') // exit from this process return; } // prepare usage variables const response = val.response; const status = response.status; l.m(mtn + "status: " + status); if (val.status) { // prepare usage variables if (!val.data.status) { // log l.e(mtn + "failure during get PageSet."); // exit from this process return; } if (val.data.status) { // prepare usage variables const launcherPage = val.data.result // set state this.setState({ page: launcherPage }, () => { }) } else l.e(mtn + "failure during get PageSet."); } else l.e(mtn + "status: " + val.status + " code: " + status) } // prepare usage variables const { drnaf_configs } = this.state; //Fire post(drnaf_configs.api_url, request, { callback: jck, }) } /** Render methods */ renderDRNAF() { // conditions if (this.state.page === null) { return <View style={{ flex: 1, backgroundColor: 'purple', }}><Text style={{ backgroundColor: 'red', alignSelf: 'center', }}>EMPTY PAGE</Text></View> } else { return <View style={{ flex: 1, backgroundColor: 'green', }}> {/* Render DRNAF Elements View */} <DRNAFView navigation={this.state.navigation} elements={this.state.page.elements} /> </View> } } /** Life cycle */ componentDidMount() { // get page sets this.apiGetPageSet(); } render() { return this.renderDRNAF(); } }