App.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  1. /**
  2. * Copyright (c) UNA, Inc - https://una.io
  3. * MIT License - https://opensource.org/licenses/MIT
  4. */
  5. import React, { Component } from 'react';
  6. import OneSignal from 'react-native-onesignal';
  7. import SplashScreen from 'react-native-splash-screen';
  8. import { WebView } from 'react-native-webview';
  9. import {
  10. Platform,
  11. StyleSheet,
  12. StyleProvider,
  13. Image,
  14. Linking,
  15. BackHandler,
  16. ActivityIndicator,
  17. Dimensions,
  18. Alert,
  19. Appearance,
  20. } from 'react-native';
  21. import {
  22. View,
  23. Container, Content,
  24. Header, Title, Left, Body, Right, Item, Input,
  25. Footer, FooterTab, Badge,
  26. Text, Icon, Button,
  27. Drawer,
  28. } from 'native-base';
  29. import RNIap, {
  30. purchaseErrorListener,
  31. purchaseUpdatedListener,
  32. type ProductPurchase,
  33. type PurchaseError
  34. } from 'react-native-iap';
  35. import JitsiMeet, { JitsiMeetView } from 'react-native-jitsi-meet';
  36. import VideoCall from './VideoCall';
  37. import ErrorPage from './ErrorPage';
  38. import { themeDark, themeLight, useTheme } from './Theme';
  39. import { version } from './package.json';
  40. type Props = {};
  41. const BASE_URL = 'https://una.io/'; // site URL
  42. const MIX_LIGHT = '12'; // template styles mix for light mode
  43. const MIX_DARK = '13'; // template styles mix for dark mode
  44. const TEMPLATE = 'protean'; // template name
  45. const TITLE = 'UNA.IO'; // app title
  46. const ONESIGNALAPPID = ''; // you can obtain one from https://onesignal.com/
  47. const PAYMENTS_CALLBACK = ''; // empty string means payment functionality is disabled
  48. export default class App extends Component<Props> {
  49. loading = false;
  50. videoCallAudio = false;
  51. purchaseUpdateSubscription = null;
  52. purchaseErrorSubscription = null;
  53. products = {};
  54. constructor(props) {
  55. super(props);
  56. var colorScheme = Appearance.getColorScheme();
  57. this.state = {
  58. url: `${BASE_URL}?skin=${TEMPLATE}&mix=${'dark' === colorScheme ? MIX_DARK : MIX_LIGHT}`,
  59. status: 'No Page Loaded',
  60. backButtonEnabled: false,
  61. forwardButtonEnabled: false,
  62. loading: this.loading,
  63. data: {},
  64. searchbar: false,
  65. key: 1,
  66. videoCall: 0,
  67. videoCallUri: false,
  68. colorScheme: colorScheme,
  69. };
  70. this.onBack.bind(this);
  71. this.onMainMenu.bind(this);
  72. this.onConferenceTerminated = this.onConferenceTerminated.bind(this);
  73. this.onConferenceJoined = this.onConferenceJoined.bind(this);
  74. this.onConferenceWillJoin = this.onConferenceWillJoin.bind(this);
  75. this.onVideoCallStart = this.onVideoCallStart.bind(this);
  76. }
  77. async onRequestPurchase (sku: string) {
  78. if ('ios' === Platform.OS)
  79. RNIap.clearTransactionIOS();
  80. try {
  81. await RNIap.requestPurchase(sku, false);
  82. } catch (err) {
  83. console.warn(err.code, err.message);
  84. Alert.alert(err.message);
  85. }
  86. }
  87. async onRequestSubscription (sku: string) {
  88. if ('ios' === Platform.OS)
  89. RNIap.clearTransactionIOS();
  90. try {
  91. await RNIap.requestSubscription(sku);
  92. } catch (err) {
  93. console.warn(err.code, err.message);
  94. Alert.alert(err.message);
  95. }
  96. }
  97. onConferenceTerminated(e) {
  98. this.endVideoCall();
  99. this.injectJavaScript("bx_mobile_apps_video_terminated(" + JSON.stringify(e.nativeEvent) + ")");
  100. }
  101. onConferenceJoined(e) {
  102. this.injectJavaScript("bx_mobile_apps_video_joined(" + JSON.stringify(e.nativeEvent) + ")");
  103. }
  104. onConferenceWillJoin(e) {
  105. this.injectJavaScript("bx_mobile_apps_video_will_join(" + JSON.stringify(e.nativeEvent) + ")");
  106. }
  107. endVideoCall() {
  108. this.videoCallAudio = false;
  109. this.setState ({
  110. videoCall: 0,
  111. videoCallUri: false,
  112. });
  113. JitsiMeet.endCall();
  114. }
  115. onVideoCallStart(sUri, bAudioOnly = false) {
  116. if (!this.state.videoCall) {
  117. this.videoCallAudio = bAudioOnly;
  118. this.setState ({
  119. videoCall: 1,
  120. videoCallUri: sUri,
  121. });
  122. }
  123. }
  124. onVideoCallToggle() {
  125. if (this.state.videoCall) {
  126. this.endVideoCall();
  127. }
  128. else {
  129. this.onVideoCallStart('testing-egr58t32g2');
  130. }
  131. }
  132. onBack() {
  133. this.endVideoCall();
  134. if (this.state.backButtonEnabled) {
  135. if ('android' === Platform.OS)
  136. this.onWebViewLoadStart(); // show loading screen
  137. this.refs.webView1.goBack();
  138. // this.injectJavaScript("window.history.go(-1)");
  139. return true;
  140. }
  141. return false;
  142. }
  143. onMainMenu() {
  144. this.endVideoCall();
  145. if (this.state.data.loggedin)
  146. this.injectJavaScript("bx_mobile_apps_show_main_menu()");
  147. else
  148. this.drawerOpen();
  149. }
  150. onBackAndMainMenu() {
  151. if (this.state.backButtonEnabled) {
  152. return this.onBack();
  153. }
  154. else {
  155. return this.onMainMenu();
  156. }
  157. }
  158. onProfileMenu() {
  159. this.endVideoCall();
  160. this.injectJavaScript("bx_mobile_apps_show_profile_menu()");
  161. return true;
  162. }
  163. onAddMenu() {
  164. this.endVideoCall();
  165. this.injectJavaScript("bx_mobile_apps_show_add_menu()");
  166. return true;
  167. }
  168. onNotificationsMenu() {
  169. this.endVideoCall();
  170. this.injectJavaScript("bx_mobile_apps_show_notifications_menu()");
  171. return true;
  172. }
  173. onMessengerMenu() {
  174. this.endVideoCall();
  175. this.injectJavaScript("bx_mobile_apps_show_messenger_menu()");
  176. return true;
  177. }
  178. onHomeMenu() {
  179. this.endVideoCall();
  180. if (`${BASE_URL}` == this.state.url || this.state.url.startsWith(`${BASE_URL}?skin=${TEMPLATE}`) || `${BASE_URL}index.php` == this.state.url) {
  181. this.injectJavaScript("bx_mobile_apps_close_sliding_menus()");
  182. } else {
  183. this.setState ({
  184. url: `${BASE_URL}?skin=${TEMPLATE}&mix=${'dark' == this.state.colorScheme ? MIX_DARK : MIX_LIGHT}`,
  185. searchbar: false,
  186. key: this.state.key + 1,
  187. });
  188. }
  189. return true;
  190. }
  191. onSearch(event) {
  192. this.onSearchCancelMenu();
  193. this.injectJavaScript(`window.location = '${BASE_URL}searchKeyword.php?keyword=${event.nativeEvent.text}';`);
  194. }
  195. onSearchCancelMenu() {
  196. this.setState ({
  197. loading: this.loading,
  198. searchbar: false,
  199. });
  200. return true;
  201. }
  202. onSearchMenu() {
  203. this.endVideoCall();
  204. this.setState ({
  205. loading: this.loading,
  206. searchbar: true,
  207. });
  208. return true;
  209. }
  210. onDrawerLoginMenu() {
  211. this.onHomeMenu();
  212. this.drawerClose();
  213. return true;
  214. }
  215. onDrawerJoinMenu() {
  216. this.injectJavaScript(`window.location = '${BASE_URL}page/create-account';`);
  217. this.drawerClose();
  218. return true;
  219. }
  220. onDrawerForgotMenu() {
  221. this.injectJavaScript(`window.location = '${BASE_URL}page/forgot-password';`);
  222. this.drawerClose();
  223. return true;
  224. }
  225. onWebViewNavigationStateChange(navState) {
  226. if (-1 != navState.url.indexOf('#') && this.state.url == navState.url.substring(0, navState.url.indexOf('#'))) {
  227. this.onWebViewLoadEnd();
  228. return;
  229. }
  230. this.setState ({
  231. url: navState.url,
  232. status: navState.title,
  233. backButtonEnabled: navState.canGoBack,
  234. forwardButtonEnabled: navState.canGoForward,
  235. searchbar: false,
  236. });
  237. }
  238. onWebViewLoadStart (syntheticEvent) {
  239. if (-1 == this.state.url.indexOf(`${BASE_URL}`)) { // loading indicator is supported on original domains only
  240. this.onWebViewLoadEnd(syntheticEvent);
  241. return;
  242. }
  243. this.loading = true;
  244. this.setState ({
  245. loading: this.loading,
  246. searchbar: false,
  247. });
  248. }
  249. onWebViewLoadEnd (syntheticEvent) {
  250. this.loading = false;
  251. this.setState ({
  252. loading: this.loading,
  253. searchbar: false,
  254. });
  255. }
  256. onWebViewRenderError () {
  257. return (
  258. <ErrorPage onReload={() => (this.reload())}></ErrorPage>
  259. );
  260. }
  261. reload() {
  262. this.refs.webView1.reload();
  263. }
  264. postMessage (data) {
  265. // posts a message to web view
  266. this.refs.webView1.postMessage(data);
  267. }
  268. injectJavaScript (script) {
  269. // executes JavaScript immediately in web view
  270. this.refs.webView1.injectJavaScript(script);
  271. }
  272. onWebViewShouldStartLoadWithRequest (event) {
  273. var aExceptionsUrls = [
  274. 'redirect_uri=', 'redirect_uri%', 'redirectUri%', // Facebook/LinkedIn Connect and other Connect apps
  275. 'signin/oauth', 'signin%2Foauth', // Google Connect
  276. '/m/oauth2', // Dolphin/UNA Connect
  277. 'api.twitter.com', // Twitter Connect
  278. ];
  279. var bExceptionUrl = aExceptionsUrls.some(e => {
  280. return -1 !== event.url.indexOf(e);
  281. });
  282. if ('about:blank' === event.url)
  283. return false;
  284. if (0 != event.url.indexOf('http') || (!bExceptionUrl && -1 == event.url.indexOf(`${BASE_URL}`) && ('android' === Platform.OS || ('click' == event.navigationType && 'ios' === Platform.OS)))) {
  285. Linking.canOpenURL(event.url).then(supported => {
  286. if (supported) {
  287. Linking.openURL(event.url);
  288. }
  289. else {
  290. console.log('Don\'t know how to open URI: ' + event.url);
  291. }
  292. return false;
  293. });
  294. return false;
  295. }
  296. if ('android' === Platform.OS)
  297. this.onWebViewLoadStart(); // show loading screen
  298. return true;
  299. }
  300. javascriptToInject () {
  301. return 'glBxNexusApp = ' + JSON.stringify({ver:version});
  302. }
  303. componentDidCatch(error, info) {
  304. SplashScreen.hide();
  305. }
  306. async componentDidMount() {
  307. Appearance.addChangeListener(({ colorScheme }) => { // not working in Android :(
  308. var s = Appearance.getColorScheme(); // colorScheme param is working incorrect in iOS13, so we need to get it explicitly
  309. if (s != this.state.colorScheme) {
  310. var sUrl = this.state.url;
  311. var sUri = `skin=${TEMPLATE}&mix=${'dark' === s ? MIX_DARK : MIX_LIGHT}`;
  312. sUrl += (-1 === sUrl.indexOf('?') ? '?' : '&') + sUri;
  313. this.setState ({
  314. colorScheme: s,
  315. url: sUrl,
  316. });
  317. }
  318. });
  319. OneSignal.setLogLevel(6, 0);
  320. OneSignal.setAppId(ONESIGNALAPPID);
  321. // OneSignal.inFocusDisplaying(0);
  322. OneSignal.promptForPushNotificationsWithUserResponse(response => {
  323. console.log("OneSignal Prompt response:", response);
  324. });
  325. OneSignal.setNotificationWillShowInForegroundHandler(notificationReceivedEvent => {
  326. console.log("OneSignal: notification will show in foreground:", notificationReceivedEvent);
  327. let notification = notificationReceivedEvent.getNotification();
  328. console.log("OneSignal notification: ", notification);
  329. const data = notification.additionalData;
  330. console.log("OneSignal additionalData: ", data);
  331. const button1 = {
  332. text: "Cancel",
  333. onPress: () => {
  334. notificationReceivedEvent.complete();
  335. },
  336. style: "cancel"
  337. };
  338. const button2 = {
  339. text: "Complete",
  340. onPress: () => {
  341. notificationReceivedEvent.complete(notification);
  342. }
  343. };
  344. Alert.alert("Complete notification?", "Test", [button1, button2], {
  345. cancelable: true
  346. });
  347. });
  348. OneSignal.setNotificationOpenedHandler(notification => {
  349. // TODO:
  350. // if ('undefined' !== typeof(openResult.notification.payload.additionalData) && 'undefined' !== typeof(openResult.notification.payload.additionalData.url) && !openResult.notification.isAppInFocus) {
  351. // this.injectJavaScript(`window.location = '${openResult.notification.payload.additionalData.url}';`);
  352. // }
  353. console.log("OneSignal: notification opened:", notification);
  354. });
  355. const deviceState = await OneSignal.getDeviceState();
  356. this.setState({
  357. isSubscribed : deviceState.isSubscribed
  358. });
  359. if (Platform.OS === 'android') {
  360. this.backHandler = BackHandler.addEventListener('hardwareBackPress', () => {
  361. if (this.state.backButtonEnabled) {
  362. this.onBack(); // works best when the goBack is async
  363. return true;
  364. }
  365. else {
  366. return false;
  367. }
  368. });
  369. }
  370. if (PAYMENTS_CALLBACK != '') {
  371. var _self = this;
  372. try {
  373. await RNIap.initConnection();
  374. const sProducts = await fetch(BASE_URL + 'modules/?r=oauth2/com/get_products_names&module=system&class=BaseServices');
  375. _self.products = await sProducts.json();
  376. await RNIap.getSubscriptions(Object.keys(_self.products));
  377. await RNIap.getProducts(Object.keys(_self.products));
  378. } catch(err) {
  379. console.warn(err);
  380. }
  381. purchaseUpdateSubscription = purchaseUpdatedListener(async (oPurchaseData: ProductPurchase) => {
  382. console.log('purchaseUpdatedListener', oPurchaseData);
  383. if ('undefined' !== typeof(oPurchaseData.transactionId) && _self.state.data.loggedin != 0) {
  384. var sProductName = 'undefined' !== typeof(oPurchaseData.productId) ? oPurchaseData.productId : null;
  385. var sTxId = 'undefined' !== typeof(oPurchaseData.transactionId) ? oPurchaseData.transactionId : '';
  386. var sTxIdOriginal = 'undefined' !== typeof(oPurchaseData.originalTransactionIdentifierIOS) ? oPurchaseData.originalTransactionIdentifierIOS : '';
  387. await fetch(PAYMENTS_CALLBACK, {
  388. method: 'POST',
  389. headers: {
  390. Accept: 'application/json',
  391. 'Content-Type': 'application/json',
  392. 'User-Agent': "UNAMobileApp/Mobile (" + Platform.OS + ")",
  393. },
  394. body: JSON.stringify({
  395. notification_type: 'INITIAL_BUY_CUSTOM',
  396. module: 'undefined' !== typeof(_self.products[sProductName]) ? _self.products[sProductName] : null,
  397. product: sProductName,
  398. count: 1,
  399. original_transaction: sTxIdOriginal,
  400. transaction: sTxId,
  401. profile_id: _self.state.data.loggedin ? _self.state.data.user_info.id : 0,
  402. original_data: oPurchaseData,
  403. })
  404. });
  405. if ('ios' === Platform.OS)
  406. RNIap.finishTransactionIOS(sTxId);
  407. }
  408. });
  409. purchaseErrorSubscription = purchaseErrorListener((error: PurchaseError) => {
  410. console.log('purchaseErrorListener', error);
  411. });
  412. }
  413. SplashScreen.hide();
  414. }
  415. componentWillUnmount() {
  416. if (this.purchaseUpdateSubscription) {
  417. this.purchaseUpdateSubscription.remove();
  418. this.purchaseUpdateSubscription = null;
  419. }
  420. if (this.purchaseErrorSubscription) {
  421. this.purchaseErrorSubscription.remove();
  422. this.purchaseErrorSubscription = null;
  423. }
  424. if (Platform.OS === 'android') {
  425. this.backHandler.remove();
  426. }
  427. }
  428. onWebViewMessage(event) {
  429. let oMsgData;
  430. try {
  431. oMsgData = JSON.parse(event.nativeEvent.data);
  432. }
  433. catch(err) {
  434. console.warn(err);
  435. return;
  436. }
  437. if ('undefined' !== typeof(oMsgData.loggedin)) {
  438. this.setState ({
  439. loading: this.loading,
  440. data: oMsgData,
  441. searchbar: false,
  442. key: 'undefined' === typeof(this.state.data.loggedin) || this.state.data.loggedin != oMsgData.loggedin ? this.state.key + 1 : this.state.key,
  443. });
  444. }
  445. if ('undefined' !== typeof(oMsgData['push_tags']) && oMsgData['push_tags'] !== false) {
  446. if ('undefined' !== typeof(oMsgData['push_tags']['email']) && oMsgData['push_tags']['email'].length) {
  447. OneSignal.setEmail(oMsgData['push_tags']['email'], oMsgData['push_tags']['email_hash'], (sError) => {
  448. if ('undefined' !== typeof(sError))
  449. console.warn("OneSignal set email error: " + sError);
  450. });
  451. delete oMsgData['push_tags']['email'];
  452. delete oMsgData['push_tags']['email_hash'];
  453. }
  454. OneSignal.sendTags(oMsgData['push_tags']);
  455. }
  456. if ('undefined' !== typeof(oMsgData['stop_loading']) && oMsgData['stop_loading']) {
  457. // this.onWebViewLoadEnd (event);
  458. }
  459. if ('undefined' !== typeof(oMsgData['video_call_start'])) {
  460. this.onVideoCallStart (oMsgData['video_call_start']['uri'], 'undefined' === typeof(oMsgData['video_call_start']['audio']) ? false : oMsgData['video_call_start']['audio']);
  461. }
  462. if ('undefined' !== typeof(oMsgData['video_call_stop']) && oMsgData['video_call_stop']) {
  463. this.endVideoCall ();
  464. }
  465. if ('undefined' !== typeof(oMsgData['request_purchase']) && oMsgData['request_purchase']) {
  466. this.onRequestPurchase (oMsgData['request_purchase']);
  467. }
  468. if ('undefined' !== typeof(oMsgData['request_subscription']) && oMsgData['request_subscription']) {
  469. this.onRequestSubscription (oMsgData['request_subscription']);
  470. }
  471. if ('undefined' !== typeof(oMsgData['goto_home']) && oMsgData['goto_home']) {
  472. this.onHomeMenu ();
  473. }
  474. if ('undefined' !== typeof(oMsgData['reload']) && oMsgData['reload']) {
  475. this.reload ();
  476. }
  477. }
  478. drawerClose () {
  479. this.refs.drawer._root.close()
  480. }
  481. drawerOpen () {
  482. this.refs.drawer._root.open()
  483. }
  484. render() {
  485. var sWebview = (
  486. <WebView
  487. useWebKit={true}
  488. ref="webView1"
  489. key={this.state.key}
  490. geolocationEnabled={true}
  491. builtInZoomControls={false}
  492. decelerationRate="normal"
  493. cacheEnabled={true}
  494. allowsLinkPreview={true}
  495. hideKeyboardAccessoryView={true}
  496. injectedJavaScript={this.javascriptToInject()}
  497. onShouldStartLoadWithRequest={this.onWebViewShouldStartLoadWithRequest.bind(this)}
  498. onNavigationStateChange={this.onWebViewNavigationStateChange.bind(this)}
  499. style={{flex: 1}}
  500. source={{uri: this.state.url }}
  501. userAgent={"UNAMobileApp/Mobile (" + Platform.OS + ")"}
  502. onMessage={this.onWebViewMessage.bind(this)}
  503. allowFileAccess={true}
  504. onLoad={this.onWebViewLoadEnd.bind(this)}
  505. onLoadStart={this.onWebViewLoadStart.bind(this)}
  506. renderError={this.onWebViewRenderError.bind(this)}
  507. />
  508. );
  509. return (
  510. <Container>
  511. <Drawer ref="drawer" content={<UnaDrawer onLogin={this.onDrawerLoginMenu.bind(this)} onJoin={this.onDrawerJoinMenu.bind(this)} onForotPassword={this.onDrawerForgotMenu.bind(this)} onClose={this.drawerClose.bind(this)} />} onClose={this.drawerClose.bind(this)}>
  512. <UnaApp
  513. webview={sWebview}
  514. state={this.state}
  515. videoCallAudio={this.videoCallAudio}
  516. onSearch={this.onSearch.bind(this)}
  517. onSearchCancelMenu={this.onSearchCancelMenu.bind(this)}
  518. onMainMenu={this.onMainMenu.bind(this)}
  519. onBackAndMainMenu={this.onBackAndMainMenu.bind(this)}
  520. onHomeMenu={this.onHomeMenu.bind(this)}
  521. onAddMenu={this.onAddMenu.bind(this)}
  522. onSearchMenu={this.onSearchMenu.bind(this)}
  523. onNotificationsMenu={this.onNotificationsMenu.bind(this)}
  524. onMessengerMenu={this.onMessengerMenu.bind(this)}
  525. onProfileMenu={this.onProfileMenu.bind(this)}
  526. onVideoCallToggle={this.onVideoCallToggle.bind(this)}
  527. onRequestSubscription={this.onRequestSubscription}
  528. onRequestPurchase={this.onRequestPurchase}
  529. onConferenceTerminated={this.onConferenceTerminated}
  530. onConferenceJoined={this.onConferenceJoined}
  531. onConferenceWillJoin={this.onConferenceWillJoin} />
  532. </Drawer>
  533. </Container>
  534. );
  535. }
  536. }
  537. function UnaApp(o) {
  538. return (<Container>
  539. {o.state.searchbar ? (
  540. <UnaToolbarSearch onSearch={o.onSearch} onSearchCancel={o.onSearchCancelMenu} />
  541. ) : (
  542. <UnaToolbar loading={o.state.loading} loggedin={o.state.data.loggedin} backButtonEnabled={o.state.backButtonEnabled} onMainMenu={o.onMainMenu} onHomeMenu={o.onHomeMenu} onSearchMenu={o.onSearchMenu} onBackAndMainMenu={o.onBackAndMainMenu} />
  543. ) }
  544. {o.state.videoCall && o.state.videoCallUri ? (
  545. <View style={styles.containerVideoCall}><VideoCall onConferenceTerminated={o.onConferenceTerminated} onConferenceJoined={o.onConferenceJoined} onConferenceWillJoin={o.onConferenceWillJoin} conferenceUri={o.state.videoCallUri} audio={o.videoCallAudio} userInfo={o.state.data.user_info} /></View>
  546. ) : (
  547. <View />
  548. )}
  549. {o.webview}
  550. {o.state.data.loggedin && (
  551. <UnaFooter bubblesNum={o.state.data.bubbles_num} bubbles={o.state.data.bubbles} onMainMenu={o.onMainMenu} onNotificationsMenu={o.onNotificationsMenu} onVideoCallToggle={o.onVideoCallToggle} onRequestPurchase={o.onRequestPurchase} onRequestSubscription={o.onRequestSubscription} onAddMenu={o.onAddMenu} onMessengerMenu={o.onMessengerMenu} onProfileMenu={o.onProfileMenu} />
  552. )}
  553. </Container>
  554. );
  555. }
  556. function UnaFooter(o) {
  557. return (
  558. <Footer style={styles.footer}>
  559. {!('decorous' == TEMPLATE && Platform.isPad) &&
  560. (<FooterTab style={styles.footerTab}>
  561. <Button vertical onPress={o.onMainMenu}>
  562. <Icon style={styles.footerIcon} name="bars" type="FontAwesome5" />
  563. </Button>
  564. </FooterTab>)
  565. }
  566. <FooterTab style={styles.footerTab}>
  567. <Button vertical onPress={o.onNotificationsMenu} badge={o.bubbles['notifications-preview'] > 0 ? true : false}>
  568. {o.bubbles['notifications-preview'] > 0 &&
  569. (<Badge><Text>{o.bubbles['notifications-preview']}</Text></Badge>)
  570. }
  571. <Icon style={styles.footerIcon} name="bell" type="FontAwesome5" solid />
  572. </Button>
  573. </FooterTab>
  574. {/*
  575. <FooterTab style={styles.footerTab}>
  576. <Button vertical onPress={o.onVideoCallToggle}>
  577. <Icon style={styles.footerIcon} name="video" type="FontAwesome5" solid />
  578. </Button>
  579. </FooterTab>
  580. */}
  581. <FooterTab style={styles.footerTab}>
  582. <Button vertical onPress={o.onAddMenu}>
  583. <Icon style={styles.footerIcon} name="plus-circle" type="FontAwesome5" solid />
  584. </Button>
  585. </FooterTab>
  586. <FooterTab style={styles.footerTab}>
  587. <Button vertical onPress={o.onMessengerMenu} badge={o.bubbles['notifications-messenger'] > 0 ? true : false}>
  588. {o.bubbles['notifications-messenger'] > 0 &&
  589. (<Badge><Text>{o.bubbles['notifications-messenger']}</Text></Badge>)
  590. }
  591. <Icon style={styles.footerIcon} name="comments" type="FontAwesome5" solid />
  592. </Button>
  593. </FooterTab>
  594. <FooterTab style={styles.footerTab}>
  595. <Button vertical onPress={o.onProfileMenu} badge={o.bubbles['account'] > 0 ? true : false}>
  596. {o.bubbles['account'] > 0 &&
  597. (<Badge><Text>{o.bubbles['account']}</Text></Badge>)
  598. }
  599. <Icon style={styles.footerIcon} name="user" type="FontAwesome5" solid />
  600. </Button>
  601. </FooterTab>
  602. </Footer>
  603. );
  604. }
  605. function UnaToolbar(o) {
  606. return (
  607. <Header androidStatusBarColor={useTheme('colors.statusBar')} transparent={false} iosBarStyle={useTheme('iosBarStyle')} style={styles.header}>
  608. <Left>
  609. {o.loading ? (
  610. <ActivityIndicator size="small" color={useTheme('colors.activityIndicator')} style={styles.loadingIndicator} />
  611. ):(
  612. o.loggedin ? (
  613. (o.backButtonEnabled || Platform.OS === 'android') &&
  614. (<Button style={Platform.OS === 'android' ? styles.buttonLeftTopAndroid : styles.buttonLeftTopIos} transparent disabled={!o.backButtonEnabled} onPress={o.onBackAndMainMenu}>
  615. <Icon name="ios-arrow-back" style={styles.headerIcon} />
  616. </Button>)
  617. ) : (
  618. <Button style={Platform.OS === 'android' ? styles.buttonLeftTopAndroid : styles.buttonLeftTopIos} transparent onPress={o.onMainMenu}>
  619. <Icon name='menu' style={styles.headerIcon} />
  620. </Button>
  621. )
  622. )}
  623. </Left>
  624. {/*
  625. <Body style={Platform.OS === 'android' && {flexDirection: 'row', justifyContent: 'flex-start'}}>
  626. */}
  627. <Body>
  628. <Title style={styles.headerTitle} onPress={o.onHomeMenu}>{TITLE}</Title>
  629. </Body>
  630. <Right>
  631. {o.loggedin && (
  632. <Button transparent>
  633. <Icon name='search' onPress={o.onSearchMenu} style={styles.headerIcon} />
  634. </Button>
  635. )}
  636. </Right>
  637. </Header>
  638. );
  639. }
  640. function UnaToolbarSearch(o) {
  641. return (
  642. <Header androidStatusBarColor={useTheme('colors.statusBar')} transparent={false} iosBarStyle={useTheme('iosBarStyle')} style={styles.header} searchBar rounded>
  643. <Item>
  644. <Icon name="search" />
  645. <Input placeholder="Search" onEndEditing={o.onSearchCancel} onSubmitEditing={o.onSearch} />
  646. </Item>
  647. <Button transparent onPress={o.onSearchCancel}>
  648. <Text style={styles.headerIcon}>Cancel</Text>
  649. </Button>
  650. </Header>
  651. );
  652. }
  653. function UnaDrawer(o) {
  654. return (
  655. <Container style={styles.drawerContainer}>
  656. <Content>
  657. <View style={styles.drawerImageContainer}>
  658. <Image style={styles.drawerImage} source={require('./img/logo-loading.png')} />
  659. </View>
  660. <Button style={styles.drawerButton} iconLeft transparent onPress={o.onLogin}>
  661. <Icon style={styles.drawerButtonIcon} name='key' type="FontAwesome5" solid />
  662. <Text style={styles.drawerButtonText}>Login</Text>
  663. </Button>
  664. <Button style={styles.drawerButton} iconLeft transparent onPress={o.onJoin}>
  665. <Icon style={styles.drawerButtonIcon} name='plus-circle' type="FontAwesome5" solid />
  666. <Text style={styles.drawerButtonText}>Join</Text>
  667. </Button>
  668. <Button style={styles.drawerButton} iconLeft transparent onPress={o.onForotPassword}>
  669. <Icon style={styles.drawerButtonIcon} name='lock' type="FontAwesome5" solid />
  670. <Text style={styles.drawerButtonText}>Forgot Password</Text>
  671. </Button>
  672. </Content>
  673. </Container>
  674. );
  675. }
  676. const styles = new StyleSheet.create({
  677. container: {
  678. backgroundColor: useTheme('colors.background'),
  679. flex: 1
  680. },
  681. header: {
  682. backgroundColor: useTheme('colors.primary'),
  683. height: 46, paddingTop:0, // tmp fix - https://github.com/GeekyAnts/NativeBase/issues/3095
  684. },
  685. headerTitle: {
  686. color: useTheme('colors.textOnPrimary'),
  687. },
  688. headerIcon: {
  689. color: useTheme('colors.textOnPrimary'),
  690. },
  691. footer: {
  692. backgroundColor: useTheme('colors.primary'),
  693. },
  694. footerTab: {
  695. backgroundColor: useTheme('colors.primary'),
  696. },
  697. footerIcon: {
  698. color: useTheme('colors.textOnPrimary'),
  699. },
  700. containerVideoCall: {
  701. backgroundColor: '#000',
  702. flex: 999999999999,
  703. },
  704. loadingIndicator: {
  705. marginLeft: 5,
  706. marginTop: 5,
  707. },
  708. buttonLeftTopAndroid: {
  709. },
  710. buttonLeftTopIos: {
  711. marginLeft: 5,
  712. },
  713. drawerContainer: {
  714. backgroundColor: useTheme('colors.drawerBackground'),
  715. },
  716. drawerImageContainer: {
  717. height:100,
  718. justifyContent: 'center',
  719. alignItems: 'center',
  720. backgroundColor: useTheme('colors.drawerBackground'),
  721. },
  722. drawerImage: {
  723. height:33.5,
  724. width:125,
  725. },
  726. drawerButton: {
  727. justifyContent: 'flex-start',
  728. },
  729. drawerButtonIcon: {
  730. width: 20,
  731. fontSize: 20,
  732. justifyContent: 'center',
  733. textAlign: 'center',
  734. color: useTheme('colors.drawerText'),
  735. },
  736. drawerButtonText: {
  737. color: useTheme('colors.drawerText'),
  738. }
  739. });