Skip to content

Commit 51b1836

Browse files
authored
test: Refactor Test3212, add option to set config from scroll view screen (#3284)
## Description This PR includes a small refactor for Test3212 that removes useCallback in favor of regular functions, and adds a button to change scrollEdgeEffect config right on the screen it is applied to - to have more paths to test. For instance, you can set the scrollEdgeEffect config to 'hard' on the first Stack screen, push the second one with ScrollView, see the configuration being applied, then click the button and see the effect changed to 'hidden'.
1 parent 4605692 commit 51b1836

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

apps/src/tests/Test3212/BottomTabsScenario.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1-
import React, { useCallback, useState } from "react";
1+
import React, { useState } from "react";
22
import { SCROLL_EDGE_EFFECT_DEFAULTS, ScrollEdgeEffects, ScrollEdgeEffectsConfigContext } from "./context";
33
import { NavigationContainer, NavigationIndependentTree } from "@react-navigation/native";
44
import { BottomTabsContainer } from "../../shared/gamma/containers/bottom-tabs/BottomTabsContainer"
55
import { Config } from "./Config";
66
import { ScrollViewTemplate } from "./ScrollViewTemplate";
77
import { ScrollView } from "react-native";
88

9+
function ConfigComponent() {
10+
// Add ScrollView for automatic insets which are missing in BottomTabsScreen
11+
return (
12+
<ScrollView>
13+
<Config title='Stack / scrollEdgeEffects:'/>
14+
</ScrollView>
15+
);
16+
}
17+
918
export function BottomTabsScenario() {
1019
const [config, setConfig] = useState<ScrollEdgeEffects>({ ...SCROLL_EDGE_EFFECT_DEFAULTS });
1120

12-
// Add ScrollView for automatic insets which are missing in BottomTabsScreen
13-
const ConfigComponent = useCallback(() => <ScrollView><Config title='BottomTabs / scrollEdgeEffects:' /></ScrollView>, []);
14-
1521
return (
1622
<NavigationIndependentTree>
1723
<ScrollEdgeEffectsConfigContext.Provider value={{ config, setConfig }}>

apps/src/tests/Test3212/ScrollViewTemplate.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
import React, { ScrollView, Text } from "react-native";
1+
import React from "react";
2+
import { Button, ScrollView, Text } from "react-native";
3+
import { useScrollEdgeEffectsConfigContext } from "./context";
24

35
export function ScrollViewTemplate() {
46
const emoji = ['😎', '🍏', '👀', '🤖', '👾', '👨‍💻'];
7+
const { setConfig } = useScrollEdgeEffectsConfigContext();
58

69
return (
7-
<ScrollView>
10+
<ScrollView contentInsetAdjustmentBehavior="automatic">
11+
<Button title="Set effects to hidden" onPress={() => {
12+
setConfig({ bottom: 'hidden', top: 'hidden', left: 'hidden', right: 'hidden' });
13+
}}/>
814
<Text style={{ fontSize: 21 }}>
915
{Array.from({ length: 1000 }).map(_ => emoji[Math.floor(Math.random() * emoji.length)])}
1016
</Text>

apps/src/tests/Test3212/StackScenario.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ import { ConfigWithNavigation } from "./Config";
44
import { NavigationContainer, NavigationIndependentTree } from "@react-navigation/native";
55
import { ScrollViewTemplate } from './ScrollViewTemplate';
66
import { SCROLL_EDGE_EFFECT_DEFAULTS, ScrollEdgeEffects, ScrollEdgeEffectsConfigContext } from './context';
7-
import { useCallback, useState } from 'react';
7+
import { useState } from 'react';
8+
9+
function ConfigComponent() {
10+
return (
11+
<ConfigWithNavigation title='Stack / scrollEdgeEffects:'/>
12+
);
13+
}
814

915
export function StackScenario() {
1016
const Stack = createNativeStackNavigator();
1117
const [config, setConfig] = useState<ScrollEdgeEffects>({...SCROLL_EDGE_EFFECT_DEFAULTS});
1218

13-
const ConfigComponent = useCallback(() => <ConfigWithNavigation title='Stack / scrollEdgeEffects:'/>, []);
14-
1519
return (
1620
<NavigationIndependentTree>
1721
<ScrollEdgeEffectsConfigContext.Provider value={{ config, setConfig }}>

0 commit comments

Comments
 (0)