App.js 32 KB

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