App.js 28 KB

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