Skip to content

Commit 1a85c8e

Browse files
committed
mocking pop event handler
1 parent 689481e commit 1a85c8e

File tree

4 files changed

+42
-16
lines changed

4 files changed

+42
-16
lines changed

lib/Mock/Components/ComponentScreen.tsx

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { Component } from 'react';
2-
import { View, Text, TouchableOpacity, Image, ImageURISource} from 'react-native';
3-
import { Navigation, ImageResource} from 'react-native-navigation';
2+
import { View, Text, TouchableOpacity, Image, ImageURISource } from 'react-native';
3+
import { Navigation, ImageResource } from 'react-native-navigation';
44
import { ComponentProps } from '../ComponentProps';
55
import { VISIBLE_SCREEN_TEST_ID } from '../constants';
66
import { LayoutStore } from '../Stores/LayoutStore';
@@ -10,8 +10,7 @@ import { events } from '../Stores/EventsStore';
1010
import _ from 'lodash';
1111
import { switchTabByIndex } from '../actions/layoutActions';
1212

13-
14-
function isURISource(src: ImageResource| undefined): src is ImageURISource {
13+
function isURISource(src: ImageResource | undefined): src is ImageURISource {
1514
return !!src && typeof src === 'object' && 'uri' in src;
1615
}
1716

@@ -36,12 +35,15 @@ export const ComponentScreen = connect(
3635
if (bottomTabsOptions?.visible === false) return null;
3736
const buttons = bottomTabs!.children!.map((child, i) => {
3837
const bottomTabOptions = child.resolveOptions().bottomTab;
39-
const icon = (bottomTabs as any).selectedIndex === i ? bottomTabOptions?.selectedIcon : bottomTabOptions?.icon;
38+
const icon =
39+
(bottomTabs as any).selectedIndex === i
40+
? bottomTabOptions?.selectedIcon
41+
: bottomTabOptions?.icon;
4042
const iconURI = isURISource(icon) ? icon.uri : undefined;
4143
return (
4244
<View key={`tab-${i}`}>
4345
<TouchableOpacity
44-
style={{padding:10}}
46+
style={{ padding: 10 }}
4547
testID={bottomTabOptions?.testID}
4648
onPress={() => {
4749
events.invokeBottomTabPressed({
@@ -51,22 +53,34 @@ export const ComponentScreen = connect(
5153
switchTabByIndex(this.props.layoutNode.getBottomTabs(), i);
5254
}}
5355
>
54-
<View style={{justifyContent: 'center', alignItems: 'center'}}>
55-
<Text>{bottomTabOptions?.badge}</Text>
56-
{iconURI && <Image style={{width: 18, height: 18, marginBottom: 5}} source={{uri: iconURI}}/>}
57-
<Text style={{fontSize: 12}}>{bottomTabOptions?.text || ''}</Text>
58-
</View>
56+
<View style={{ justifyContent: 'center', alignItems: 'center' }}>
57+
<Text>{bottomTabOptions?.badge}</Text>
58+
{iconURI && (
59+
<Image
60+
style={{ width: 18, height: 18, marginBottom: 5 }}
61+
source={{ uri: iconURI }}
62+
/>
63+
)}
64+
<Text style={{ fontSize: 12 }}>{bottomTabOptions?.text || ''}</Text>
65+
</View>
5966
</TouchableOpacity>
6067
</View>
6168
);
6269
});
6370

6471
return (
65-
<View
66-
testID={bottomTabsOptions?.testID}
67-
style={{flexDirection: 'row',justifyContent: 'center', width: '100%', backgroundColor: '#F0F2F5'}}>
72+
<View
73+
testID={bottomTabsOptions?.testID}
74+
style={{
75+
flexDirection: 'row',
76+
justifyContent: 'center',
77+
width: '100%',
78+
backgroundColor: '#F0F2F5',
79+
}}
80+
>
6881
{buttons}
69-
</View>);
82+
</View>
83+
);
7084
}
7185

7286
render() {

lib/Mock/Stores/EventsStore.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
ComponentDidDisappearEvent,
33
ComponentWillAppearEvent,
44
ModalDismissedEvent,
5+
ScreenPoppedEvent,
56
} from '../../src/interfaces/ComponentEvents';
67
import { ComponentDidAppearEvent, NavigationButtonPressedEvent } from '../../src/index';
78
import { BottomTabPressedEvent, CommandCompletedEvent } from '../../src/interfaces/Events';
@@ -14,6 +15,7 @@ export const events = {
1415
modalDismissed: [(_event: ModalDismissedEvent) => {}],
1516
bottomTabPressed: [(_event: BottomTabPressedEvent) => {}],
1617
commandCompleted: [(_event: CommandCompletedEvent) => {}],
18+
screenPopped: [(_event: ScreenPoppedEvent) => {}],
1719
invokeComponentWillAppear: (event: ComponentWillAppearEvent) => {
1820
events.componentWillAppear &&
1921
events.componentWillAppear.forEach((listener) => {
@@ -56,4 +58,10 @@ export const events = {
5658
listener(event);
5759
});
5860
},
61+
invokeScreenPopped: (event: ScreenPoppedEvent) => {
62+
events.screenPopped &&
63+
events.screenPopped.forEach((listener) => {
64+
listener(event);
65+
});
66+
},
5967
};

lib/Mock/mocks/NativeCommandsSender.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ export class NativeCommandsSender {
5555
LayoutStore.getLayoutById(componentId).getStack().children
5656
) as ComponentNode;
5757
LayoutStore.pop(componentId);
58+
events.invokeScreenPopped({
59+
componentId,
60+
});
5861
resolve(poppedChild.nodeId);
5962
this.reportCommandCompletion(CommandName.Pop, commandId);
6063
});

lib/Mock/mocks/NativeEventsReceiver.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,9 @@ export class NativeEventsReceiver {
152152
}
153153

154154
public registerScreenPoppedListener(
155-
_callback: (event: ScreenPoppedEvent) => void
155+
callback: (event: ScreenPoppedEvent) => void
156156
): EmitterSubscription {
157+
events.screenPopped.push(callback);
157158
return {
158159
remove: () => {},
159160
} as EmitterSubscription;

0 commit comments

Comments
 (0)