App.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865
  1. /**
  2. * Copyright (c) UNA, Inc - https://una.io
  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://una.io/'; // 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 = 'protean'; // template name
  66. const TITLE = 'UNA.IO | 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)))) {
  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 sWebview = (
  529. <WebView
  530. useWebKit={true}
  531. ref="webView1"
  532. key={this.state.key}
  533. geolocationEnabled={true}
  534. builtInZoomControls={false}
  535. decelerationRate="normal"
  536. cacheEnabled={true}
  537. allowsLinkPreview={true}
  538. hideKeyboardAccessoryView={true}
  539. injectedJavaScript={this.javascriptToInject()}
  540. onShouldStartLoadWithRequest={this.onWebViewShouldStartLoadWithRequest.bind(this)}
  541. onNavigationStateChange={this.onWebViewNavigationStateChange.bind(this)}
  542. style={styles.webview}
  543. source={{uri: `${BASE_URL}?skin=${TEMPLATE}&mix=${'dark' === this.state.colorScheme ? MIX_DARK : MIX_LIGHT}` }}
  544. userAgent={"UNAMobileApp/Mobile (" + Platform.OS + ")"}
  545. onMessage={this.onWebViewMessage.bind(this)}
  546. allowFileAccess={true}
  547. onLoad={this.onWebViewLoadEnd.bind(this)}
  548. onLoadStart={this.onWebViewLoadStart.bind(this)}
  549. renderError={this.onWebViewRenderError.bind(this)}
  550. startInLoadingState={true}
  551. renderLoading={() => <View style={styles.webviewFirstLoad} bg={useTheme('colors.background')}><ActivityIndicator size="large" color={useTheme('colors.activityIndicator')} style={styles.webviewFirstLoadIndicator} /></View>}
  552. />
  553. );
  554. return (
  555. <NativeBaseProvider>
  556. {this.state.searchbar ? (
  557. <UnaToolbarSearch onSearch={this.onSearch} onSearchCancel={this.onSearchCancelMenu} />
  558. ) : (
  559. <UnaToolbar 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} />
  560. ) }
  561. {this.state.videoCall && this.state.videoCallUri ? (
  562. <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>
  563. ) : (
  564. <View />
  565. )}
  566. {sWebview}
  567. { 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 /> }
  568. {this.state.data.loggedin && (
  569. <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} />
  570. )}
  571. </NativeBaseProvider>
  572. );
  573. }
  574. }
  575. function UnaFooter(o) {
  576. return (
  577. <HStack bg={useTheme('colors.primary')} borderColor={useTheme('colors.toolbarBorder')} alignItems="center" safeAreaBottom style={styles.footer}>
  578. {!('decorous' == TEMPLATE && Platform.isPad) &&
  579. (<Pressable py="3" flex={1} style={styles.footerTab}>
  580. <IconButton icon={<Icons.Apps size="xl" style={styles.footerIcon} color={useTheme('colors.textOnPrimary')} />} onPress={o.onMainMenu} />
  581. </Pressable>)
  582. }
  583. <Pressable py="3" flex={1} style={styles.footerTab}>
  584. <IconButton icon={<Icons.Bell size="xl"style={styles.footerIcon} color={useTheme('colors.textOnPrimary')} />} onPress={o.onNotificationsMenu} />
  585. {o.bubbles['notifications-preview'] > 0 && (<Badge num={o.bubbles['notifications-preview']} />)}
  586. </Pressable>
  587. {/*
  588. <Pressable py="3" flex={1} style={styles.footerTab}>
  589. <Center><IconButton icon={<Icons.Video size="xl" style={styles.footerIcon} color={useTheme('colors.textOnPrimary')} />} onPress={o.onVideoCallToggle} /></Center>
  590. </Pressable>
  591. */}
  592. <Pressable py="3" flex={1} style={styles.footerTab}>
  593. <IconButton icon={<Icons.Plus size="xl" style={styles.footerIcon} color={useTheme('colors.textOnPrimary')} />} onPress={o.onAddMenu} />
  594. </Pressable>
  595. <Pressable py="3" flex={1} style={styles.footerTab}>
  596. <IconButton icon={<Icons.Chat size="xl" style={styles.footerIcon} color={useTheme('colors.textOnPrimary')} />} onPress={o.onMessengerMenu} />
  597. {o.bubbles['notifications-messenger'] > 0 && (<Badge num={o.bubbles['notifications-messenger']} />)}
  598. </Pressable>
  599. <Pressable py="3" flex={1} style={styles.footerTab}>
  600. <IconButton icon={<Icons.User size="xl" style={styles.footerIcon} color={useTheme('colors.textOnPrimary')} />} onPress={o.onProfileMenu} />
  601. {o.bubbles['account'] > 0 && (<Badge num={o.bubbles['account']} />)}
  602. </Pressable>
  603. </HStack>
  604. );
  605. }
  606. function UnaToolbar(o) {
  607. return (
  608. <View style={{borderBottomColor: useTheme('colors.toolbarBorder'), borderBottomWidth:0.5}}>
  609. <StatusBar bg={useTheme('colors.statusBar')} barStyle={useTheme('barStyle')} />
  610. <Box safeAreaTop bg={useTheme('colors.statusBar')} />
  611. <HStack bg={useTheme('colors.primary')} px="1" py="1" justifyContent="space-between" alignItems="center" w="100%" style={styles.header}>
  612. <HStack alignItems="center">
  613. {o.loading ? (
  614. <ActivityIndicator size="small" color={useTheme('colors.activityIndicator')} style={styles.loadingIndicator} />
  615. ):(
  616. o.loggedin ? (
  617. (<IconButton icon={<Icons.Back size="lg" color={o.backButtonEnabled ? useTheme('colors.textOnPrimary') : useTheme('colors.textOnPrimaryDisabled')} style={styles.headerIcon} />} onPress={o.onBack} />)
  618. ) : (
  619. <IconButton icon={<Icons.Bars size="lg" color={useTheme('colors.textOnPrimary')} style={styles.headerIcon} />} onPress={o.onDrawerToggle} />
  620. )
  621. )}
  622. {!o.title || TITLE == o.title || o.loading ? (
  623. <Image alt="Logo" style={styles.headerImage} source={require('./img/logo.png')} />
  624. ) : (
  625. <Text color={useTheme('colors.textOnPrimary')} numberOfLines={1} ellipsizeMode="tail" style={styles.headerTitle}>{o.title}</Text>
  626. )}
  627. </HStack>
  628. <HStack>
  629. {o.loggedin && (<IconButton icon={<Icons.Search size="lg" color={useTheme('colors.textOnPrimary')} style={styles.headerIcon} />} onPress={o.onSearchMenu} />)}
  630. </HStack>
  631. </HStack>
  632. </View>
  633. );
  634. }
  635. function UnaToolbarSearch(o) {
  636. return (
  637. <View style={{borderBottomColor: useTheme('colors.toolbarBorder'), borderBottomWidth:0.5}}>
  638. <StatusBar bg={useTheme('colors.statusBar')} barStyle={useTheme('barStyle')} />
  639. <Box safeAreaTop bg={useTheme('colors.statusBar')} />
  640. <HStack bg={useTheme('colors.primary')} px="1" py="1" justifyContent="space-between" alignItems="center" w="100%" style={styles.header}>
  641. <HStack alignItems="center" style={styles.searchInputContainer}>
  642. <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} />
  643. <IconButton icon={<Icons.Cross size="sm" color={useTheme('colors.textOnPrimary')} />} onPress={o.onSearchCancel} />
  644. </HStack>
  645. </HStack>
  646. </View>
  647. );
  648. }
  649. function UnaDrawer(o) {
  650. const {StatusBarManager} = NativeModules;
  651. const height = StatusBarManager.HEIGHT;
  652. return (
  653. <Box bg={useTheme('colors.drawerBackground')} borderColor={useTheme('colors.drawerBorder')} style={[styles.drawerContainer, {top:height + ('ios' === Platform.OS ? 50 : 25)}]} shadow={2}>
  654. <VStack space={2}>
  655. <Pressable style={styles.drawerButton} iconLeft transparent onPress={o.onLogin}>
  656. <HStack>
  657. <Icons.In size="md" color={useTheme('colors.drawerText')} style={styles.drawerButtonIcon} />
  658. <Text fontSize="md" color={useTheme('colors.drawerText')} style={styles.drawerButtonText}>Login</Text>
  659. </HStack>
  660. </Pressable>
  661. <Pressable style={styles.drawerButton} iconLeft transparent onPress={o.onJoin}>
  662. <HStack>
  663. <Icons.PlusCircle size="md" color={useTheme('colors.drawerText')} style={styles.drawerButtonIcon} />
  664. <Text fontSize="md" color={useTheme('colors.drawerText')} style={styles.drawerButtonText}>Join</Text>
  665. </HStack>
  666. </Pressable>
  667. <Pressable style={styles.drawerButton} iconLeft transparent onPress={o.onForotPassword}>
  668. <HStack>
  669. <Icons.Question size="md" color={useTheme('colors.drawerText')} style={styles.drawerButtonIcon} />
  670. <Text fontSize="md" color={useTheme('colors.drawerText')} style={styles.drawerButtonText}>Forgot Password</Text>
  671. </HStack>
  672. </Pressable>
  673. </VStack>
  674. </Box>
  675. );
  676. }
  677. function Badge(o) {
  678. return (
  679. <Box style={styles.badge}><Text style={styles.badgeText}>{o.num}</Text></Box>
  680. );
  681. }
  682. const styles = new StyleSheet.create({
  683. webview: {
  684. flex: 1,
  685. backgroundColor: 'transparent',
  686. },
  687. webviewFirstLoad: {
  688. flex: 9999999999,
  689. justifyContent: 'center',
  690. alignItems: 'center',
  691. },
  692. header: {
  693. height: 50,
  694. },
  695. headerTitle: {
  696. fontSize: 18,
  697. fontWeight: 'bold',
  698. },
  699. headerImage: {
  700. width: 99,
  701. height: 28,
  702. },
  703. searchInputContainer: {
  704. paddingLeft:5,
  705. },
  706. searchInputItem: {
  707. borderWidth: 1,
  708. },
  709. footer: {
  710. borderTopWidth: 0.5,
  711. },
  712. containerVideoCall: {
  713. backgroundColor: '#000',
  714. flex: 9999999999,
  715. },
  716. loadingIndicator: {
  717. width:44,
  718. height:44,
  719. },
  720. drawerContainer: {
  721. position: 'absolute',
  722. top:0,
  723. left:0,
  724. width:250,
  725. borderWidth: 0.5,
  726. padding:20,
  727. },
  728. drawerButton: {
  729. justifyContent: 'flex-start',
  730. },
  731. drawerButtonIcon: {
  732. top:3,
  733. marginRight:10,
  734. justifyContent: 'center',
  735. textAlign: 'center',
  736. },
  737. badge: {
  738. backgroundColor:'red',
  739. color:'white',
  740. position:'absolute',
  741. top:4,
  742. right:11,
  743. paddingLeft:4,
  744. paddingRight:4,
  745. borderRadius:3
  746. },
  747. badgeText: {
  748. color:'white',
  749. fontSize: 11,
  750. fontWeight: 'bold',
  751. },
  752. });