Skip to content

Commit

Permalink
Issue #24 and #16: Implemented auto-update fetching and font loading
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0is1 committed Oct 16, 2024
1 parent 2896860 commit 28b04f7
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"expo-dev-client": "~4.0.27",
"expo-font": "^12.0.10",
"expo-status-bar": "~1.12.1",
"expo-updates": "~0.25.25",
"expo-updates": "^0.25.27",
"html-entities": "^2.5.2",
"react": "18.2.0",
"react-native": "0.74.5",
Expand Down
21 changes: 20 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,30 @@ import DashboardScreen from "./screens/DashboardScreen/DashboardScreen";
import AlbumViewerScreen from "./screens/AlbumViewerScreen/AlbumViewerScreen";
import Constants from "./constants/constants";
import FloatingPlayerScreen from "./screens/FloatingPlayerScreen/FloatingPlayerScreen";
import autoUpdateFetch from "./utils/autoUpdateFetch";
import loadFonts from "./utils/fontLoader";

const Stack = createStackNavigator();
const constants = new Constants();

export default function App() {
const [playerInitialized, setPlayerInitialized] = useState(false);
const [fontsLoaded, setFontsLoaded] = useState(false);

useEffect(() => {
const loadAppFonts = async () => {
await loadFonts();
setFontsLoaded(true);
};

loadAppFonts();
}, []);

useEffect(() => {
if (!__DEV__) {
autoUpdateFetch();
}
}, []);

useEffect(() => {
const initializePlayer = async () => {
Expand All @@ -28,13 +46,14 @@ export default function App() {
return async () => await TrackPlayer.destroy();
}
} catch (error) {
// setPlayerInitialized(true);
console.error("Error setting up player", error);
}
};
initializePlayer();
}, [playerInitialized]);

return (
return fontsLoaded && (
<PlayerProvider>
<StatusBar backgroundColor={"transparent"} translucent />
<NavigationContainer>
Expand Down
19 changes: 19 additions & 0 deletions src/utils/autoUpdateFetch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as Updates from "expo-updates";
import { ToastAndroid } from "react-native";

const autoUpdateFetch = async () => {
try {
const update = await Updates.checkForUpdateAsync();
if (update.isAvailable) {
await Updates.fetchUpdateAsync();
await Updates.reloadAsync();
}
} catch (error) {
ToastAndroid.show(
`Error fetching latest Expo update: ${error}`,
ToastAndroid.SHORT,
);
}
};

export default autoUpdateFetch;
12 changes: 12 additions & 0 deletions src/utils/fontLoader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as Font from 'expo-font';

const loadFonts = async () => {
await Font.loadAsync({
'Poppins-Regular': require('../../assets/fonts/Poppins/Poppins-Regular.ttf'),
'Poppins-Bold': require('../../assets/fonts/Poppins/Poppins-Bold.ttf'),
'Poppins-Thin': require("../../assets/fonts/Poppins/Poppins-Thin.ttf")
});
};


export default loadFonts

0 comments on commit 28b04f7

Please sign in to comment.