App.js 31 KB

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