update app version when refreshing feed
This commit is contained in:
1
App.js
1
App.js
@@ -30,6 +30,7 @@ import Slideshow from './Views/Slideshow.js';
|
|||||||
import SongPlayer from './Views/SongPlayer.js';
|
import SongPlayer from './Views/SongPlayer.js';
|
||||||
import { Platform } from 'react-native';
|
import { Platform } from 'react-native';
|
||||||
import { PostHogProvider } from 'posthog-react-native'
|
import { PostHogProvider } from 'posthog-react-native'
|
||||||
|
import * as Updates from 'expo-updates';
|
||||||
|
|
||||||
|
|
||||||
const Tab = createBottomTabNavigator();
|
const Tab = createBottomTabNavigator();
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import PostPopularUsers from '../components/PostPopularUsers.js';
|
|||||||
import GlobalState from '../contexts/GlobalState.js';
|
import GlobalState from '../contexts/GlobalState.js';
|
||||||
import * as Linking from 'expo-linking';
|
import * as Linking from 'expo-linking';
|
||||||
import { posthog } from './../PostHog.js';
|
import { posthog } from './../PostHog.js';
|
||||||
|
import * as Updates from 'expo-updates';
|
||||||
|
|
||||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||||
|
|
||||||
@@ -48,6 +48,20 @@ const handleURL = (url, navigation) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function onFetchUpdateAsync() {
|
||||||
|
try {
|
||||||
|
const update = await Updates.checkForUpdateAsync();
|
||||||
|
|
||||||
|
if (update.isAvailable) {
|
||||||
|
await Updates.fetchUpdateAsync();
|
||||||
|
await Updates.reloadAsync();
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// You can also add an alert() to see the error message in case of an error when fetching updates.
|
||||||
|
console.log(`Error fetching latest Expo update: ${error}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let Feed = ({ navigation, route }) => {
|
let Feed = ({ navigation, route }) => {
|
||||||
let [Posts, setPosts] = useState([]);
|
let [Posts, setPosts] = useState([]);
|
||||||
const flatListRef = React.useRef()
|
const flatListRef = React.useRef()
|
||||||
@@ -93,6 +107,7 @@ let Feed = ({ navigation, route }) => {
|
|||||||
if (cacheFeed.length && subscribed) setPosts(cacheFeed);
|
if (cacheFeed.length && subscribed) setPosts(cacheFeed);
|
||||||
console.log("Feed from server")
|
console.log("Feed from server")
|
||||||
}
|
}
|
||||||
|
await onFetchUpdateAsync();
|
||||||
flatListRef.current.scrollToOffset({ animated: true, offset: 0 })
|
flatListRef.current.scrollToOffset({ animated: true, offset: 0 })
|
||||||
let posts = await API.getPosts();
|
let posts = await API.getPosts();
|
||||||
if (subscribed) {
|
if (subscribed) {
|
||||||
|
|||||||
Reference in New Issue
Block a user