Delay in switching from Dark mode to Light mode and vice versa in React Native

In my React Native app, I’m experiencing a delay when switching between Dark mode and Light mode, particularly noticeable due to the time it takes to reflect the change. My app’s data structure includes several keys, each containing approximately 50 song data entries. Could you advise on how to optimize the mode switch to reduce this delay and ensure a smoother transition between modes?

My data like…

{
   "key1":[],
   "key2":[],
   ....
}

One key contain approx 50 song data

import React, {memo, useCallback, useMemo} from 'react';
import {View, Text, TouchableOpacity, FlatList} from 'react-native';
import {Image} from 'expo-image';
import {createStyles} from './StyleHorizontalList';
import {useNavigation} from '@react-navigation/native';
import {useDispatch} from 'react-redux';
import {setVerticalListData, setTrackListID} from '../../../../redux/actions';
import {useTheme} from '../../../../Theme/ThemeContext';

//! ------------OUTER FUNCIONS ---------------

const replace150with500 = url => {
  return url?.replace('150x150', '500x500') || url;
};

const Box = memo(({item, module_template, GoToAllTracks, styles}) => (
  <TouchableOpacity
    style={styles.box}
    onPress={() => GoToAllTracks('tracks', item.token, item.type)}>
    <View style={styles.image_box(module_template)}>
      <Image
        style={styles.poster}
        source={{uri: replace150with500(item?.image) || ''}}
        contentPosition={'top center'}
        alt="poster"
        onError={error => console.log('Image failed to load', error)}
      />
    </View>
    <Text
      style={styles.title(module_template)}
      numberOfLines={1}
      ellipsizeMode="tail">
      {item?.title ?? ''}
    </Text>
    <Text
      style={styles.desc(module_template)}
      numberOfLines={1}
      ellipsizeMode="tail">
      {item?.desc}
    </Text>
  </TouchableOpacity>
));

const SongType = [
  {
    module_name: 'Trending',
    module_template: 'trending',
  },
  {
    module_name: 'New Release Hindi',
    module_template: 'newReleaseHindi',
  },
  {
    module_name: 'New Release English',
    module_template: 'newReleaseEnglish',
  },
  {
    module_name: 'Top Artist',
    module_template: 'topArtist',
  },
  {
    module_name: 'Top Charts',
    module_template: 'topCharts',
  },
  {
    module_name: 'Hindi Playlist',
    module_template: 'topPlaylistHindi',
  },
  {
    module_name: 'English Playlist',
    module_template: 'topPlaylistEnglish',
  },
];

//! ------------COMPONENT START ---------------

const HorizontalList = ({data}) => {
  const navigation = useNavigation();
  const dispatch = useDispatch();
  const {theme} = useTheme();
  const {colors} = theme;
  // console.log('Render');
  const styles = useMemo(() => createStyles(colors), [colors]);

  const GoToVertical = useCallback(
    (route, module_data, module_name, module_template) => {
      const obj = {
        data: module_data,
        title: module_name,
        type: module_template,
      };
      dispatch(setVerticalListData(obj));
      navigation.navigate(route);
    },
    [dispatch],
  );

  const GoToAllTracks = useCallback(
    (route, token, type) => {
      const obj = {
        token,
        type,
      };
      dispatch(setTrackListID(obj));
      navigation.navigate(route);
    },
    [dispatch, navigation],
  );

  const renderBox = useCallback(
    ({item, module_template}) => (
      <Box
        item={item}
        module_template={module_template}
        GoToAllTracks={GoToAllTracks}
        styles={styles}
      />
    ),
    [GoToAllTracks, styles],
  );

  return (
    <>
      {SongType.map((item, index) => (
        <View style={styles.container} key={index}>
          <View style={styles.head}>
            <Text style={styles.module_name}>{item.module_name}</Text>
            <TouchableOpacity
              onPress={() =>
                GoToVertical(
                  'alllist',
                  data[item.module_template],
                  item.module_name,
                  item.module_template,
                )
              }>
              <Text style={styles.more}>See All</Text>
            </TouchableOpacity>
          </View>
          <View style={styles.box_container}>
            <FlatList
              data={data[item.module_template]}
              horizontal
              renderItem={renderBox}
              initialNumToRender={10}
              keyExtractor={(item, index) => index.toString()}
              showsHorizontalScrollIndicator={false}
              contentContainerStyle={{gap: 10}}
            />
          </View>
        </View>
      ))}
    </>
  );
};

export default memo(HorizontalList);

 

New contributor

Jivo Tec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật