import React, { useEffect, useState } from 'react'; import { ActivityIndicator, Linking, View } from 'react-native'; import { ScrollView } from 'react-native-gesture-handler'; import { useThemeStore } from '../../../stores/use-theme-store'; import { STORE_LINK } from '../../../utils/constants'; import { SIZE } from '../../../utils/size'; import { Button } from '../../ui/button'; import { SvgView } from '../../ui/svg'; import Seperator from '../../ui/seperator'; import Heading from '../../ui/typography/heading'; import Paragraph from '../../ui/typography/paragraph'; import Config from 'react-native-config'; import deviceInfoModule from 'react-native-device-info'; import { checkVersion } from 'react-native-check-version'; import { ProgressBarComponent } from '../../ui/svg/lazy'; const UPDATE_SVG = color => ``; export const Update = ({ version: appVersion, fwdRef }) => { const colors = useThemeStore(state => state.colors); const [version, setVersion] = useState(appVersion); let notes = version?.notes ? version.notes.replace('Thank you for using Notesnook!', '').split('- ') : ['Bug fixes and performance improvements']; notes = notes?.map(n => n.replace(/\n/g, '')); const isGithubRelease = Config.GITHUB_RELEASE === 'true'; const getSupportedAbi = () => { let abi = deviceInfoModule.supportedAbisSync(); let armv8a = abi.find(a => a === 'arm64-v8a'); let armv7 = abi.find(a => a === 'armeabi-v7a'); return armv8a || armv7 || abi[0]; }; const GITHUB_URL = !version || !version.needsUpdate ? null : `https://github.com/streetwriters/notesnook/releases/download/${ version.version }-android/notesnook-${getSupportedAbi()}.apk`; const GITHUB_PAGE_URL = !version || !version.needsUpdate ? null : `https://github.com/streetwriters/notesnook/releases/tag/${version.version}-android`; useEffect(() => { if (!version) { (async () => { try { console.log('checking for new version'); let v = await checkVersion(); setVersion(v); } catch (e) { setVersion({ needsUpdate: false }); } })(); } }, []); return ( {!version || !version?.needsUpdate ? ( <> {!version ? ( <> }> Checking for new version ) : ( No new updates are available )} ) : ( <> Update available v{version.version} has been released {isGithubRelease ? 'on Github' : ''} { fwdRef?.current?.handleChildScrollEnd(); }} style={{ width: '100%' }} > Release notes: {notes.map(item => ( • {item} ))}