update app version when refreshing feed

This commit is contained in:
Adolfo Reyna
2025-02-06 23:28:31 -05:00
parent 7cf6f99503
commit a85d9779b8
2 changed files with 29 additions and 13 deletions

1
App.js
View File

@@ -30,6 +30,7 @@ import Slideshow from './Views/Slideshow.js';
import SongPlayer from './Views/SongPlayer.js';
import { Platform } from 'react-native';
import { PostHogProvider } from 'posthog-react-native'
import * as Updates from 'expo-updates';
const Tab = createBottomTabNavigator();

View File

@@ -6,7 +6,7 @@ import PostPopularUsers from '../components/PostPopularUsers.js';
import GlobalState from '../contexts/GlobalState.js';
import * as Linking from 'expo-linking';
import { posthog } from './../PostHog.js';
import * as Updates from 'expo-updates';
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 [Posts, setPosts] = useState([]);
const flatListRef = React.useRef()
@@ -93,6 +107,7 @@ let Feed = ({ navigation, route }) => {
if (cacheFeed.length && subscribed) setPosts(cacheFeed);
console.log("Feed from server")
}
await onFetchUpdateAsync();
flatListRef.current.scrollToOffset({ animated: true, offset: 0 })
let posts = await API.getPosts();
if (subscribed) {