mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-04-21 16:51:57 +00:00
homescreen optimization
This commit is contained in:
parent
52740c26de
commit
c1503f0614
2 changed files with 95 additions and 49 deletions
|
|
@ -15,7 +15,8 @@ import {
|
|||
Image,
|
||||
Modal,
|
||||
Pressable,
|
||||
Alert
|
||||
Alert,
|
||||
InteractionManager
|
||||
} from 'react-native';
|
||||
import { FlashList } from '@shopify/flash-list';
|
||||
import { useNavigation, useFocusEffect } from '@react-navigation/native';
|
||||
|
|
@ -146,8 +147,10 @@ const HomeScreen = () => {
|
|||
stremioService.getInstalledAddonsAsync()
|
||||
]);
|
||||
|
||||
// Set hasAddons state based on whether we have any addons
|
||||
// Set hasAddons state based on whether we have any addons - ensure on main thread
|
||||
InteractionManager.runAfterInteractions(() => {
|
||||
setHasAddons(addons.length > 0);
|
||||
});
|
||||
|
||||
const catalogSettings = catalogSettingsJson ? JSON.parse(catalogSettingsJson) : {};
|
||||
|
||||
|
|
@ -245,16 +248,20 @@ const HomeScreen = () => {
|
|||
items
|
||||
};
|
||||
|
||||
// Update the catalog at its specific position
|
||||
// Update the catalog at its specific position - ensure on main thread
|
||||
InteractionManager.runAfterInteractions(() => {
|
||||
setCatalogs(prevCatalogs => {
|
||||
const newCatalogs = [...prevCatalogs];
|
||||
newCatalogs[currentIndex] = catalogContent;
|
||||
return newCatalogs;
|
||||
});
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
if (__DEV__) console.error(`[HomeScreen] Failed to load ${catalog.name} from ${addon.name}:`, error);
|
||||
} finally {
|
||||
// Update loading count - ensure on main thread
|
||||
InteractionManager.runAfterInteractions(() => {
|
||||
setLoadedCatalogCount(prev => {
|
||||
const next = prev + 1;
|
||||
// Exit loading screen as soon as first catalog finishes
|
||||
|
|
@ -263,6 +270,7 @@ const HomeScreen = () => {
|
|||
}
|
||||
return next;
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -275,14 +283,18 @@ const HomeScreen = () => {
|
|||
|
||||
totalCatalogsRef.current = catalogIndex;
|
||||
|
||||
// Initialize catalogs array with proper length
|
||||
// Initialize catalogs array with proper length - ensure on main thread
|
||||
InteractionManager.runAfterInteractions(() => {
|
||||
setCatalogs(new Array(catalogIndex).fill(null));
|
||||
});
|
||||
|
||||
// Start processing the catalog queue
|
||||
processCatalogQueue();
|
||||
} catch (error) {
|
||||
if (__DEV__) console.error('[HomeScreen] Error in progressive catalog loading:', error);
|
||||
InteractionManager.runAfterInteractions(() => {
|
||||
setCatalogsLoading(false);
|
||||
});
|
||||
}
|
||||
}, []);
|
||||
|
||||
|
|
|
|||
|
|
@ -100,9 +100,18 @@ const AnimatedImage = memo(({
|
|||
useEffect(() => {
|
||||
if (source?.uri) {
|
||||
opacity.value = withTiming(1, { duration: 300 });
|
||||
} else {
|
||||
opacity.value = 0;
|
||||
}
|
||||
}, [source?.uri]);
|
||||
|
||||
// Cleanup on unmount
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
opacity.value = 0;
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Animated.View style={[style, animatedStyle]}>
|
||||
<Image
|
||||
|
|
@ -137,6 +146,14 @@ const AnimatedText = memo(({
|
|||
useEffect(() => {
|
||||
opacity.value = withDelay(delay, withTiming(1, { duration: 250 }));
|
||||
translateY.value = withDelay(delay, withTiming(0, { duration: 250 }));
|
||||
}, [delay]);
|
||||
|
||||
// Cleanup on unmount
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
opacity.value = 0;
|
||||
translateY.value = 20;
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
|
|
@ -166,6 +183,14 @@ const AnimatedView = memo(({
|
|||
useEffect(() => {
|
||||
opacity.value = withDelay(delay, withTiming(1, { duration: 250 }));
|
||||
translateY.value = withDelay(delay, withTiming(0, { duration: 250 }));
|
||||
}, [delay]);
|
||||
|
||||
// Cleanup on unmount
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
opacity.value = 0;
|
||||
translateY.value = 20;
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
|
|
@ -388,6 +413,7 @@ const ProviderFilter = memo(({
|
|||
initialNumToRender={5}
|
||||
maxToRenderPerBatch={3}
|
||||
windowSize={3}
|
||||
removeClippedSubviews={true}
|
||||
getItemLayout={(data, index) => ({
|
||||
length: 100, // Approximate width of each item
|
||||
offset: 100 * index,
|
||||
|
|
@ -1598,6 +1624,9 @@ export const StreamsScreen = () => {
|
|||
useEffect(() => {
|
||||
return () => {
|
||||
isMounted.current = false;
|
||||
// Clear scraper logo cache to free memory
|
||||
scraperLogoCache.clear();
|
||||
scraperLogoCachePromise = null;
|
||||
};
|
||||
}, []);
|
||||
|
||||
|
|
@ -1856,6 +1885,11 @@ export const StreamsScreen = () => {
|
|||
windowSize={3}
|
||||
removeClippedSubviews={true}
|
||||
showsVerticalScrollIndicator={false}
|
||||
getItemLayout={(data, index) => ({
|
||||
length: 78, // Approximate height of StreamCard (68 minHeight + 10 marginBottom)
|
||||
offset: 78 * index,
|
||||
index,
|
||||
})}
|
||||
/>
|
||||
) : (
|
||||
// Empty section placeholder
|
||||
|
|
|
|||
Loading…
Reference in a new issue