App.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879
  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 | Community Management System'; // homepage 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: '',
  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. status: '',
  186. searchbar: false,
  187. key: this.state.key + 1,
  188. });
  189. }
  190. return true;
  191. }
  192. onSearch(event) {
  193. this.onSearchCancelMenu();
  194. this.injectJavaScript(`window.location = '${BASE_URL}searchKeyword.php?keyword=${event.nativeEvent.text}';`);
  195. }
  196. onSearchCancelMenu() {
  197. this.setState ({
  198. loading: this.loading,
  199. searchbar: false,
  200. });
  201. return true;
  202. }
  203. onSearchMenu() {
  204. this.endVideoCall();
  205. this.setState ({
  206. loading: this.loading,
  207. searchbar: true,
  208. });
  209. return true;
  210. }
  211. onDrawerLoginMenu() {
  212. this.onHomeMenu();
  213. this.drawerClose();
  214. return true;
  215. }
  216. onDrawerJoinMenu() {
  217. this.injectJavaScript(`window.location = '${BASE_URL}page/create-account';`);
  218. this.drawerClose();
  219. return true;
  220. }
  221. onDrawerForgotMenu() {
  222. this.injectJavaScript(`window.location = '${BASE_URL}page/forgot-password';`);
  223. this.drawerClose();
  224. return true;
  225. }
  226. onWebViewNavigationStateChange(navState) {
  227. if (-1 != navState.url.indexOf('#') && this.state.url == navState.url.substring(0, navState.url.indexOf('#'))) {
  228. this.onWebViewLoadEnd();
  229. return;
  230. }
  231. this.setState ({
  232. url: navState.url,
  233. status: navState.title,
  234. backButtonEnabled: navState.canGoBack,
  235. forwardButtonEnabled: navState.canGoForward,
  236. searchbar: false,
  237. });
  238. }
  239. onWebViewLoadStart (syntheticEvent) {
  240. if (-1 == this.state.url.indexOf(`${BASE_URL}`)) { // loading indicator is supported on original domains only
  241. this.onWebViewLoadEnd(syntheticEvent);
  242. return;
  243. }
  244. this.loading = true;
  245. this.setState ({
  246. loading: this.loading,
  247. searchbar: false,
  248. });
  249. }
  250. onWebViewLoadEnd (syntheticEvent) {
  251. this.loading = false;
  252. this.setState ({
  253. loading: this.loading,
  254. searchbar: false,
  255. });
  256. }
  257. onWebViewRenderError () {
  258. return (
  259. <ErrorPage onReload={() => (this.reload())}></ErrorPage>
  260. );
  261. }
  262. reload() {
  263. this.refs.webView1.reload();
  264. }
  265. postMessage (data) {
  266. // posts a message to web view
  267. this.refs.webView1.postMessage(data);
  268. }
  269. injectJavaScript (script) {
  270. // executes JavaScript immediately in web view
  271. this.refs.webView1.injectJavaScript(script);
  272. }
  273. onWebViewShouldStartLoadWithRequest (event) {
  274. var aExceptionsUrls = [
  275. 'redirect_uri=', 'redirect_uri%', 'redirectUri%', // Facebook/LinkedIn Connect and other Connect apps
  276. 'signin/oauth', 'signin%2Foauth', // Google Connect
  277. '/m/oauth2', // Dolphin/UNA Connect
  278. 'api.twitter.com', // Twitter Connect
  279. ];
  280. var bExceptionUrl = aExceptionsUrls.some(e => {
  281. return -1 !== event.url.indexOf(e);
  282. });
  283. if ('about:blank' === event.url)
  284. return false;
  285. if (0 != event.url.indexOf('http') || (!bExceptionUrl && -1 == event.url.indexOf(`${BASE_URL}`) && ('android' === Platform.OS || ('click' == event.navigationType && 'ios' === Platform.OS)))) {
  286. Linking.canOpenURL(event.url).then(supported => {
  287. if (supported) {
  288. Linking.openURL(event.url);
  289. }
  290. else {
  291. console.log('Don\'t know how to open URI: ' + event.url);
  292. }
  293. return false;
  294. });
  295. return false;
  296. }
  297. if ('android' === Platform.OS)
  298. this.onWebViewLoadStart(); // show loading screen
  299. return true;
  300. }
  301. javascriptToInject () {
  302. return 'glBxNexusApp = ' + JSON.stringify({ver:version});
  303. }
  304. componentDidCatch(error, info) {
  305. SplashScreen.hide();
  306. }
  307. async componentDidMount() {
  308. Appearance.addChangeListener(({ colorScheme }) => { // not working in Android :(
  309. var s = Appearance.getColorScheme(); // colorScheme param is working incorrect in iOS13, so we need to get it explicitly
  310. if (s != this.state.colorScheme) {
  311. var sUrl = this.state.url;
  312. var sUri = `skin=${TEMPLATE}&mix=${'dark' === s ? MIX_DARK : MIX_LIGHT}`;
  313. sUrl += (-1 === sUrl.indexOf('?') ? '?' : '&') + sUri;
  314. this.setState ({
  315. colorScheme: s,
  316. url: sUrl,
  317. });
  318. }
  319. });
  320. OneSignal.setLogLevel(6, 0);
  321. OneSignal.setAppId(ONESIGNALAPPID);
  322. // OneSignal.inFocusDisplaying(0);
  323. OneSignal.promptForPushNotificationsWithUserResponse(response => {
  324. console.log("OneSignal Prompt response:", response);
  325. });
  326. OneSignal.setNotificationWillShowInForegroundHandler(notificationReceivedEvent => {
  327. console.log("OneSignal: notification will show in foreground:", notificationReceivedEvent);
  328. let notification = notificationReceivedEvent.getNotification();
  329. console.log("OneSignal notification: ", notification);
  330. const data = notification.additionalData;
  331. console.log("OneSignal additionalData: ", data);
  332. const button1 = {
  333. text: "Cancel",
  334. onPress: () => {
  335. notificationReceivedEvent.complete();
  336. },
  337. style: "cancel"
  338. };
  339. const button2 = {
  340. text: "Complete",
  341. onPress: () => {
  342. notificationReceivedEvent.complete(notification);
  343. }
  344. };
  345. Alert.alert("Complete notification?", "Test", [button1, button2], {
  346. cancelable: true
  347. });
  348. });
  349. OneSignal.setNotificationOpenedHandler(notification => {
  350. // TODO:
  351. // if ('undefined' !== typeof(openResult.notification.payload.additionalData) && 'undefined' !== typeof(openResult.notification.payload.additionalData.url) && !openResult.notification.isAppInFocus) {
  352. // this.injectJavaScript(`window.location = '${openResult.notification.payload.additionalData.url}';`);
  353. // }
  354. console.log("OneSignal: notification opened:", notification);
  355. });
  356. const deviceState = await OneSignal.getDeviceState();
  357. this.setState({
  358. isSubscribed : deviceState.isSubscribed
  359. });
  360. if (Platform.OS === 'android') {
  361. this.backHandler = BackHandler.addEventListener('hardwareBackPress', () => {
  362. if (this.state.backButtonEnabled) {
  363. this.onBack(); // works best when the goBack is async
  364. return true;
  365. }
  366. else {
  367. return false;
  368. }
  369. });
  370. }
  371. if (PAYMENTS_CALLBACK != '') {
  372. var _self = this;
  373. try {
  374. await RNIap.initConnection();
  375. const sProducts = await fetch(BASE_URL + 'modules/?r=oauth2/com/get_products_names&module=system&class=BaseServices');
  376. _self.products = await sProducts.json();
  377. await RNIap.getSubscriptions(Object.keys(_self.products));
  378. await RNIap.getProducts(Object.keys(_self.products));
  379. } catch(err) {
  380. console.warn(err);
  381. }
  382. purchaseUpdateSubscription = purchaseUpdatedListener(async (oPurchaseData: ProductPurchase) => {
  383. console.log('purchaseUpdatedListener', oPurchaseData);
  384. if ('undefined' !== typeof(oPurchaseData.transactionId) && _self.state.data.loggedin != 0) {
  385. var sProductName = 'undefined' !== typeof(oPurchaseData.productId) ? oPurchaseData.productId : null;
  386. var sTxId = 'undefined' !== typeof(oPurchaseData.transactionId) ? oPurchaseData.transactionId : '';
  387. var sTxIdOriginal = 'undefined' !== typeof(oPurchaseData.originalTransactionIdentifierIOS) ? oPurchaseData.originalTransactionIdentifierIOS : '';
  388. await fetch(PAYMENTS_CALLBACK, {
  389. method: 'POST',
  390. headers: {
  391. Accept: 'application/json',
  392. 'Content-Type': 'application/json',
  393. 'User-Agent': "UNAMobileApp/Mobile (" + Platform.OS + ")",
  394. },
  395. body: JSON.stringify({
  396. notification_type: 'INITIAL_BUY_CUSTOM',
  397. module: 'undefined' !== typeof(_self.products[sProductName]) ? _self.products[sProductName] : null,
  398. product: sProductName,
  399. count: 1,
  400. original_transaction: sTxIdOriginal,
  401. transaction: sTxId,
  402. profile_id: _self.state.data.loggedin ? _self.state.data.user_info.id : 0,
  403. original_data: oPurchaseData,
  404. })
  405. });
  406. if ('ios' === Platform.OS)
  407. RNIap.finishTransactionIOS(sTxId);
  408. }
  409. });
  410. purchaseErrorSubscription = purchaseErrorListener((error: PurchaseError) => {
  411. console.log('purchaseErrorListener', error);
  412. });
  413. }
  414. SplashScreen.hide();
  415. }
  416. componentWillUnmount() {
  417. if (this.purchaseUpdateSubscription) {
  418. this.purchaseUpdateSubscription.remove();
  419. this.purchaseUpdateSubscription = null;
  420. }
  421. if (this.purchaseErrorSubscription) {
  422. this.purchaseErrorSubscription.remove();
  423. this.purchaseErrorSubscription = null;
  424. }
  425. if (Platform.OS === 'android') {
  426. this.backHandler.remove();
  427. }
  428. }
  429. onWebViewMessage(event) {
  430. let oMsgData;
  431. try {
  432. oMsgData = JSON.parse(event.nativeEvent.data);
  433. }
  434. catch(err) {
  435. console.warn(err);
  436. return;
  437. }
  438. if ('undefined' !== typeof(oMsgData.loggedin)) {
  439. this.setState ({
  440. loading: this.loading,
  441. data: oMsgData,
  442. searchbar: false,
  443. key: 'undefined' === typeof(this.state.data.loggedin) || this.state.data.loggedin != oMsgData.loggedin ? this.state.key + 1 : this.state.key,
  444. });
  445. }
  446. if ('undefined' !== typeof(oMsgData['push_tags']) && oMsgData['push_tags'] !== false) {
  447. if ('undefined' !== typeof(oMsgData['push_tags']['email']) && oMsgData['push_tags']['email'].length) {
  448. OneSignal.setEmail(oMsgData['push_tags']['email'], oMsgData['push_tags']['email_hash'], (sError) => {
  449. if ('undefined' !== typeof(sError))
  450. console.warn("OneSignal set email error: " + sError);
  451. });
  452. delete oMsgData['push_tags']['email'];
  453. delete oMsgData['push_tags']['email_hash'];
  454. }
  455. OneSignal.sendTags(oMsgData['push_tags']);
  456. }
  457. if ('undefined' !== typeof(oMsgData['stop_loading']) && oMsgData['stop_loading']) {
  458. // this.onWebViewLoadEnd (event);
  459. }
  460. if ('undefined' !== typeof(oMsgData['video_call_start'])) {
  461. this.onVideoCallStart (oMsgData['video_call_start']['uri'], 'undefined' === typeof(oMsgData['video_call_start']['audio']) ? false : oMsgData['video_call_start']['audio']);
  462. }
  463. if ('undefined' !== typeof(oMsgData['video_call_stop']) && oMsgData['video_call_stop']) {
  464. this.endVideoCall ();
  465. }
  466. if ('undefined' !== typeof(oMsgData['request_purchase']) && oMsgData['request_purchase']) {
  467. this.onRequestPurchase (oMsgData['request_purchase']);
  468. }
  469. if ('undefined' !== typeof(oMsgData['request_subscription']) && oMsgData['request_subscription']) {
  470. this.onRequestSubscription (oMsgData['request_subscription']);
  471. }
  472. if ('undefined' !== typeof(oMsgData['goto_home']) && oMsgData['goto_home']) {
  473. this.onHomeMenu ();
  474. }
  475. if ('undefined' !== typeof(oMsgData['reload']) && oMsgData['reload']) {
  476. this.reload ();
  477. }
  478. }
  479. drawerClose () {
  480. this.refs.drawer._root.close()
  481. }
  482. drawerOpen () {
  483. this.refs.drawer._root.open()
  484. }
  485. render() {
  486. var sWebview = (
  487. <WebView
  488. useWebKit={true}
  489. ref="webView1"
  490. key={this.state.key}
  491. geolocationEnabled={true}
  492. builtInZoomControls={false}
  493. decelerationRate="normal"
  494. cacheEnabled={true}
  495. allowsLinkPreview={true}
  496. hideKeyboardAccessoryView={true}
  497. injectedJavaScript={this.javascriptToInject()}
  498. onShouldStartLoadWithRequest={this.onWebViewShouldStartLoadWithRequest.bind(this)}
  499. onNavigationStateChange={this.onWebViewNavigationStateChange.bind(this)}
  500. style={styles.webview}
  501. source={{uri: this.state.url }}
  502. userAgent={"UNAMobileApp/Mobile (" + Platform.OS + ")"}
  503. onMessage={this.onWebViewMessage.bind(this)}
  504. allowFileAccess={true}
  505. onLoad={this.onWebViewLoadEnd.bind(this)}
  506. onLoadStart={this.onWebViewLoadStart.bind(this)}
  507. renderError={this.onWebViewRenderError.bind(this)}
  508. startInLoadingState={true}
  509. renderLoading={() => <View style={styles.webviewFirstLoad}><ActivityIndicator size="large" color={useTheme('colors.activityIndicator')} style={styles.webviewFirstLoadIndicator} /></View>}
  510. />
  511. );
  512. return (
  513. <Container>
  514. <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)}>
  515. <UnaApp
  516. webview={sWebview}
  517. state={this.state}
  518. videoCallAudio={this.videoCallAudio}
  519. onSearch={this.onSearch.bind(this)}
  520. onSearchCancelMenu={this.onSearchCancelMenu.bind(this)}
  521. onMainMenu={this.onMainMenu.bind(this)}
  522. onBackAndMainMenu={this.onBackAndMainMenu.bind(this)}
  523. onHomeMenu={this.onHomeMenu.bind(this)}
  524. onAddMenu={this.onAddMenu.bind(this)}
  525. onSearchMenu={this.onSearchMenu.bind(this)}
  526. onNotificationsMenu={this.onNotificationsMenu.bind(this)}
  527. onMessengerMenu={this.onMessengerMenu.bind(this)}
  528. onProfileMenu={this.onProfileMenu.bind(this)}
  529. onVideoCallToggle={this.onVideoCallToggle.bind(this)}
  530. onRequestSubscription={this.onRequestSubscription}
  531. onRequestPurchase={this.onRequestPurchase}
  532. onConferenceTerminated={this.onConferenceTerminated}
  533. onConferenceJoined={this.onConferenceJoined}
  534. onConferenceWillJoin={this.onConferenceWillJoin} />
  535. </Drawer>
  536. </Container>
  537. );
  538. }
  539. }
  540. function UnaApp(o) {
  541. return (<Container>
  542. {o.state.searchbar ? (
  543. <UnaToolbarSearch onSearch={o.onSearch} onSearchCancel={o.onSearchCancelMenu} />
  544. ) : (
  545. <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} title={o.state.status} url={o.state.url} />
  546. ) }
  547. {o.state.videoCall && o.state.videoCallUri ? (
  548. <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>
  549. ) : (
  550. <View />
  551. )}
  552. {o.webview}
  553. {o.state.data.loggedin && (
  554. <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} />
  555. )}
  556. </Container>
  557. );
  558. }
  559. function UnaFooter(o) {
  560. return (
  561. <Footer style={styles.footer}>
  562. {!('decorous' == TEMPLATE && Platform.isPad) &&
  563. (<FooterTab style={styles.footerTab}>
  564. <Button vertical onPress={o.onMainMenu}>
  565. <Icon style={styles.footerIcon} name="menu-outline" type="Ionicons" />
  566. </Button>
  567. </FooterTab>)
  568. }
  569. <FooterTab style={styles.footerTab}>
  570. <Button vertical onPress={o.onNotificationsMenu} badge={o.bubbles['notifications-preview'] > 0 ? true : false}>
  571. {o.bubbles['notifications-preview'] > 0 &&
  572. (<Badge><Text>{o.bubbles['notifications-preview']}</Text></Badge>)
  573. }
  574. <Icon style={styles.footerIcon} name="notifications-outline" type="Ionicons" solid />
  575. </Button>
  576. </FooterTab>
  577. {/*
  578. <FooterTab style={styles.footerTab}>
  579. <Button vertical onPress={o.onVideoCallToggle}>
  580. <Icon style={styles.footerIcon} name="videocam-outline" type="Ionicons" solid />
  581. </Button>
  582. </FooterTab>
  583. */}
  584. <FooterTab style={styles.footerTab}>
  585. <Button vertical onPress={o.onAddMenu}>
  586. <Icon style={styles.footerIcon} name="add-circle-outline" type="Ionicons" solid />
  587. </Button>
  588. </FooterTab>
  589. <FooterTab style={styles.footerTab}>
  590. <Button vertical onPress={o.onMessengerMenu} badge={o.bubbles['notifications-messenger'] > 0 ? true : false}>
  591. {o.bubbles['notifications-messenger'] > 0 &&
  592. (<Badge><Text>{o.bubbles['notifications-messenger']}</Text></Badge>)
  593. }
  594. <Icon style={styles.footerIcon} name="chatbubbles-outline" type="Ionicons" solid />
  595. </Button>
  596. </FooterTab>
  597. <FooterTab style={styles.footerTab}>
  598. <Button vertical onPress={o.onProfileMenu} badge={o.bubbles['account'] > 0 ? true : false}>
  599. {o.bubbles['account'] > 0 &&
  600. (<Badge><Text>{o.bubbles['account']}</Text></Badge>)
  601. }
  602. <Icon style={styles.footerIcon} name="person-circle-outline" type="Ionicons" solid />
  603. </Button>
  604. </FooterTab>
  605. </Footer>
  606. );
  607. }
  608. function UnaToolbar(o) {
  609. return (
  610. <Header androidStatusBarColor={useTheme('colors.statusBar')} transparent={false} iosBarStyle={useTheme('iosBarStyle')} style={styles.header}>
  611. <Left>
  612. {o.loading ? (
  613. <ActivityIndicator size="small" color={useTheme('colors.activityIndicator')} style={styles.loadingIndicator} />
  614. ):(
  615. o.loggedin ? (
  616. (o.backButtonEnabled || Platform.OS === 'android') &&
  617. (<Button style={Platform.OS === 'android' ? styles.buttonLeftTopAndroid : styles.buttonLeftTopIos} transparent disabled={!o.backButtonEnabled} onPress={o.onBackAndMainMenu}>
  618. <Icon name="arrow-back-outline" type="Ionicons" style={styles.headerIcon} />
  619. </Button>)
  620. ) : (
  621. <Button style={Platform.OS === 'android' ? styles.buttonLeftTopAndroid : styles.buttonLeftTopIos} transparent onPress={o.onMainMenu}>
  622. <Icon name="menu-outline" type="Ionicons" style={styles.headerIcon} />
  623. </Button>
  624. )
  625. )}
  626. </Left>
  627. <Body>
  628. {!o.title || TITLE == o.title || o.loading ? (
  629. <Image style={styles.headerImage} source={require('./img/logo.png')} />
  630. ) : (
  631. <Text numberOfLines={1} ellipsizeMode="tail" style={styles.headerTitle}>{o.title}</Text>
  632. )}
  633. </Body>
  634. <Right>
  635. {o.loggedin && (
  636. <Button transparent>
  637. <Icon name='search-outline' type="Ionicons" onPress={o.onSearchMenu} style={styles.headerIcon} />
  638. </Button>
  639. )}
  640. </Right>
  641. </Header>
  642. );
  643. }
  644. function UnaToolbarSearch(o) {
  645. return (
  646. <Header androidStatusBarColor={useTheme('colors.statusBar')} transparent={false} iosBarStyle={useTheme('iosBarStyle')} style={styles.header} searchBar rounded noShadow>
  647. <Item style={styles.searchInputItem}>
  648. <Input placeholder="Search..." onEndEditing={o.onSearchCancel} onSubmitEditing={o.onSearch} style={styles.searchInput} placeholderTextColor={useTheme('colors.searchInputPlaceholderText')} />
  649. </Item>
  650. <Button transparent onPress={o.onSearchCancel}>
  651. <Icon name='close-outline' type="Ionicons" style={styles.headerIcon} />
  652. </Button>
  653. </Header>
  654. );
  655. }
  656. function UnaDrawer(o) {
  657. return (
  658. <Container style={styles.drawerContainer}>
  659. <Content>
  660. <View style={styles.drawerImageContainer}>
  661. <Image style={styles.drawerImage} source={require('./img/logo-drawer.png')} />
  662. </View>
  663. <Button style={styles.drawerButton} iconLeft transparent onPress={o.onLogin}>
  664. <Icon style={styles.drawerButtonIcon} name='key-outline' type="Ionicons" solid />
  665. <Text style={styles.drawerButtonText}>Login</Text>
  666. </Button>
  667. <Button style={styles.drawerButton} iconLeft transparent onPress={o.onJoin}>
  668. <Icon style={styles.drawerButtonIcon} name='add-circle-outline' type="Ionicons" solid />
  669. <Text style={styles.drawerButtonText}>Join</Text>
  670. </Button>
  671. <Button style={styles.drawerButton} iconLeft transparent onPress={o.onForotPassword}>
  672. <Icon style={styles.drawerButtonIcon} name='lock-closed-outline' type="Ionicons" solid />
  673. <Text style={styles.drawerButtonText}>Forgot Password</Text>
  674. </Button>
  675. </Content>
  676. </Container>
  677. );
  678. }
  679. const styles = new StyleSheet.create({
  680. container: {
  681. backgroundColor: useTheme('colors.background'),
  682. flex: 1
  683. },
  684. webview: {
  685. flex: 1,
  686. backgroundColor: 'transparent',
  687. },
  688. webviewFirstLoad: {
  689. flex: 9999999999,
  690. backgroundColor: useTheme('colors.background'),
  691. justifyContent: 'center',
  692. alignItems: 'center',
  693. },
  694. webviewFirstLoadIndicator: {
  695. },
  696. header: {
  697. backgroundColor: useTheme('colors.primary'),
  698. height: 46, paddingTop:0, // tmp fix - https://github.com/GeekyAnts/NativeBase/issues/3095
  699. borderBottomWidth: 0.5,
  700. borderBottomColor: useTheme('colors.toolbarBorder'),
  701. },
  702. headerTitle: {
  703. color: useTheme('colors.textOnPrimary'),
  704. fontSize: 22,
  705. },
  706. headerImage: {
  707. width: 99,
  708. height: 28,
  709. },
  710. headerIcon: {
  711. color: useTheme('colors.textOnPrimary'),
  712. fontSize: 28,
  713. },
  714. searchInputItem: {
  715. borderColor: useTheme('colors.searchInputBorder'),
  716. borderRightWidth: 1,
  717. borderTopWidth: 1,
  718. borderLeftWidth: 1,
  719. borderBottomWidth: 1,
  720. backgroundColor: useTheme('colors.searchInputBackground'),
  721. },
  722. searchInput: {
  723. color: useTheme('colors.searchInputText'),
  724. paddingLeft: 15,
  725. paddingRight: 15
  726. },
  727. footer: {
  728. backgroundColor: useTheme('colors.primary'),
  729. borderTopWidth: 0.5,
  730. borderTopColor: useTheme('colors.toolbarBorder'),
  731. },
  732. footerTab: {
  733. backgroundColor: useTheme('colors.primary'),
  734. },
  735. footerIcon: {
  736. color: useTheme('colors.textOnPrimary'),
  737. fontSize: 28,
  738. },
  739. containerVideoCall: {
  740. backgroundColor: '#000',
  741. flex: 9999999999,
  742. },
  743. loadingIndicator: {
  744. marginLeft: 5,
  745. marginTop: 5,
  746. },
  747. buttonLeftTopAndroid: {
  748. },
  749. buttonLeftTopIos: {
  750. },
  751. drawerContainer: {
  752. backgroundColor: useTheme('colors.drawerBackground'),
  753. },
  754. drawerImageContainer: {
  755. height:100,
  756. justifyContent: 'center',
  757. alignItems: 'center',
  758. backgroundColor: useTheme('colors.drawerBackground'),
  759. },
  760. drawerImage: {
  761. height:33.5,
  762. width:125,
  763. },
  764. drawerButton: {
  765. justifyContent: 'flex-start',
  766. },
  767. drawerButtonIcon: {
  768. width: 20,
  769. fontSize: 20,
  770. justifyContent: 'center',
  771. textAlign: 'center',
  772. color: useTheme('colors.drawerText'),
  773. },
  774. drawerButtonText: {
  775. color: useTheme('colors.drawerText'),
  776. },
  777. });