Skip to content

Commit 9af94aa

Browse files
committed
Change useFooterAccordionEvents hook to a service component
This service component is a leaf component (it has no children), and therefore it is cheap to re-render.
1 parent a94a46a commit 9af94aa

File tree

3 files changed

+27
-23
lines changed

3 files changed

+27
-23
lines changed

src/components/Main.tsx

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import { RewardsCardDashboardScene as RewardsCardListSceneComponent } from '../p
2525
import { RewardsCardWelcomeScene as RewardsCardWelcomeSceneComponent } from '../plugins/gui/scenes/RewardsCardWelcomeScene'
2626
import { SepaFormScene } from '../plugins/gui/scenes/SepaFormScene'
2727
import { defaultAccount } from '../reducers/CoreReducer'
28-
import { useFooterAccordionEvents } from '../state/SceneFooterState'
2928
import { useDispatch, useSelector } from '../types/reactRedux'
3029
import { AppParamList, NavigationBase } from '../types/routerTypes'
3130
import { logEvent } from '../util/tracking'
@@ -235,9 +234,6 @@ export const Main = () => {
235234
const [legacyLanding, setLegacyLanding] = React.useState<boolean | undefined>(isMaestro() ? false : undefined)
236235
const [hasInitialScenesLoaded, setHasInitialScenesLoaded] = React.useState(false)
237236

238-
// Register footer accordion events
239-
useFooterAccordionEvents()
240-
241237
// Match react navigation theme background with the patina theme
242238
const reactNavigationTheme = React.useMemo(() => {
243239
return {
@@ -270,21 +266,25 @@ export const Main = () => {
270266
'setLegacyLanding'
271267
)
272268

273-
return legacyLanding == null ? (
274-
<LoadingSplashScreen />
275-
) : (
276-
<NavigationContainer theme={reactNavigationTheme}>
277-
<Stack.Navigator
278-
initialRouteName={ENV.USE_WELCOME_SCREENS && !legacyLanding ? 'gettingStarted' : 'login'}
279-
screenOptions={{
280-
headerShown: false
281-
}}
282-
>
283-
<Stack.Screen name="edgeApp" component={EdgeApp} />
284-
<Stack.Screen name="gettingStarted" component={GettingStartedScene} />
285-
<Stack.Screen name="login" component={LoginScene} options={{ animationEnabled: hasInitialScenesLoaded }} />
286-
</Stack.Navigator>
287-
</NavigationContainer>
269+
return (
270+
<>
271+
{legacyLanding == null ? (
272+
<LoadingSplashScreen />
273+
) : (
274+
<NavigationContainer theme={reactNavigationTheme}>
275+
<Stack.Navigator
276+
initialRouteName={ENV.USE_WELCOME_SCREENS && !legacyLanding ? 'gettingStarted' : 'login'}
277+
screenOptions={{
278+
headerShown: false
279+
}}
280+
>
281+
<Stack.Screen name="edgeApp" component={EdgeApp} />
282+
<Stack.Screen name="gettingStarted" component={GettingStartedScene} />
283+
<Stack.Screen name="login" component={LoginScene} options={{ animationEnabled: hasInitialScenesLoaded }} />
284+
</Stack.Navigator>
285+
</NavigationContainer>
286+
)}
287+
</>
288288
)
289289
}
290290

src/components/services/Services.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { useHandler } from '../../hooks/useHandler'
1212
import { useRefresher } from '../../hooks/useRefresher'
1313
import { makeStakePlugins } from '../../plugins/stake-plugins/stakePlugins'
1414
import { defaultAccount } from '../../reducers/CoreReducer'
15+
import { FooterAccordionEventService } from '../../state/SceneFooterState'
1516
import { useDispatch, useSelector } from '../../types/reactRedux'
1617
import { NavigationBase } from '../../types/routerTypes'
1718
import { height, ratioHorizontal, ratioVertical, width } from '../../util/scaling'
@@ -148,6 +149,7 @@ export function Services(props: Props) {
148149
{account == null ? null : <WalletConnectService account={account} />}
149150
<WalletLifecycle />
150151
<WipeLogsService />
152+
<FooterAccordionEventService />
151153
</>
152154
)
153155
}

src/state/SceneFooterState.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ export const useSceneFooterRender = (renderFn: FooterRender = defaultFooterRende
122122
}
123123

124124
/**
125-
* This hook registers event handlers for the footer's expanded/collapsed states.
126-
* This hook is only required to be used once within the app (Main). Using this
127-
* hook multiple times will cause thrashing for the footer state shared values.
125+
* This is a component service which registers event handlers for the footer's
126+
* expanded/collapsed states. Using this component multiple times will cause
127+
* thrashing for the footer state shared values.
128128
*/
129-
export const useFooterAccordionEvents = () => {
129+
export const FooterAccordionEventService = () => {
130130
const { scrollState } = useSceneScrollContext()
131131
const { scrollBeginEvent, scrollEndEvent, scrollMomentumBeginEvent, scrollMomentumEndEvent, scrollY } = scrollState
132132

@@ -224,6 +224,8 @@ export const useFooterAccordionEvents = () => {
224224
},
225225
[keepOpen]
226226
)
227+
228+
return null
227229
}
228230

229231
/**

0 commit comments

Comments
 (0)