wix / react-native-ui-lib

UI Components Library for React Native
https://wix.github.io/react-native-ui-lib/
MIT License
6.47k stars 707 forks source link

Issue with the lazy attribute in a TabController.TabPage component #2969

Open L2Develop96 opened 7 months ago

L2Develop96 commented 7 months ago

Description

Related to

Steps to reproduce

Use lazy attribute on TabController.TabPage :

 <TabController.TabPage
            key={index}
            index={index}
            lazy
            renderLoading={() => <LoaderScreen />}>
            <ScrollView>{component()}</ScrollView>
</TabController.TabPage>

Expected behavior

UI & Logic (whole component) should be lazy loaded and only when the tab is visited and not at the first mount of the tabs.

Actual behavior

UI is being rendered correctly (lazy is being applied) Logic such as effects & dispatchers are being executed instantly even when the tab is not yet visited.

More Info

Code snippet

import { useTheme } from '@/theme';
import { TabsItems } from '@/types/schemas/types';
import React, { useState } from 'react';
import { ScrollView, Text, TouchableOpacity, View } from 'react-native';
import { LoaderScreen, TabController } from 'react-native-ui-lib';

const Tabs: React.FC<{ items: TabsItems }> = ({ items }) => {
  const [currentTabIndex, setTabIndex] = useState(0);

  return (
    <TabController
      initialIndex={currentTabIndex}
      items={[{}, {}]}
      asCarousel
      onChangeIndex={setTabIndex}>
      <TabBar
        currentTabIndex={currentTabIndex}
        setTabIndex={setTabIndex}
        items={items}
      />
      <TabController.PageCarousel>
        {items.map(({ component }, index) => (
          <TabController.TabPage
            key={index}
            index={index}
            lazy
            renderLoading={() => <LoaderScreen />}>
            <ScrollView>{component()}</ScrollView>
          </TabController.TabPage>
        ))}
      </TabController.PageCarousel>
    </TabController>
  );
};

export default Tabs;

Screenshots/Video

Environment

Affected platforms

SupriyaPKalghatgi commented 5 months ago

Same issue

SupriyaPKalghatgi commented 5 months ago

@Inbal-Tish Can you please check this

L2Develop96 commented 3 months ago

Any updates on this?