Skip to content

Commit

Permalink
Pass componentName to NavigationProps (#7757)
Browse files Browse the repository at this point in the history
* Pass componentName to NavigationProps

* Update NavigationComponentProps.ts
  • Loading branch information
yogevbd authored Jul 30, 2023
1 parent 1dd7eed commit 39e3cb1
Show file tree
Hide file tree
Showing 49 changed files with 117 additions and 117 deletions.
6 changes: 5 additions & 1 deletion lib/src/components/ComponentWrapper.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ describe('ComponentWrapper', () => {
renderer.create(<NavigationComponent componentId={'component123'} />);
expect(myComponentProps).toEqual({
componentId: 'component123',
componentName,
numberProp: 1,
stringProp: 'hello',
objectProp: { a: 2 },
Expand Down Expand Up @@ -251,7 +252,10 @@ describe('ComponentWrapper', () => {
const NavigationComponent = uut.wrap(componentName, generator, store, componentEventsObserver);
const tree = renderer.create(<NavigationComponent componentId={'component123'} />);
expect(tree.root.findByType(View)).toBeDefined();
expect(tree.root.findByType(MyComponent).props).toEqual({ componentId: 'component123' });
expect(tree.root.findByType(MyComponent).props).toEqual({
componentId: 'component123',
componentName,
});
});

it('sets component instance in store when constructed', () => {
Expand Down
6 changes: 5 additions & 1 deletion lib/src/components/ComponentWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ export class ComponentWrapper {

render() {
return (
<GeneratedComponentClass {...this.state.allProps} componentId={this.state.componentId} />
<GeneratedComponentClass
{...this.state.allProps}
componentId={this.state.componentId}
componentName={componentName}
/>
);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/interfaces/NavigationComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import {
ComponentDidAppearEvent,
ComponentDidDisappearEvent,
} from './ComponentEvents';
import { NavigationComponentProps } from './NavigationComponentProps';
import { NavigationProps } from './NavigationComponentProps';
import { Options } from './Options';

export class NavigationComponent<Props = {}, State = {}, Snapshot = any> extends React.Component<
Props & NavigationComponentProps,
Props & NavigationProps,
State,
Snapshot
> {
Expand Down
8 changes: 8 additions & 0 deletions lib/src/interfaces/NavigationComponentProps.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/**
* @deprecated This type replaced with NavigationProps
*/
export interface NavigationComponentProps {
componentId: string;
}

export interface NavigationProps {
componentId: string;
componentName: string;
}
6 changes: 3 additions & 3 deletions lib/src/interfaces/NavigationFunctionComponent.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { NavigationComponentProps } from './NavigationComponentProps';
import { NavigationProps } from './NavigationComponentProps';
import { Options } from './Options';

export interface NavigationFunctionComponent<Props = {}>
extends React.FunctionComponent<Props & NavigationComponentProps> {
options?: ((props: Props & NavigationComponentProps) => Options) | Options;
extends React.FunctionComponent<Props & NavigationProps> {
options?: ((props: Props & NavigationProps) => Options) | Options;
}
4 changes: 2 additions & 2 deletions playground/src/components/TopBarBackground.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { StyleSheet, View, ViewStyle } from 'react-native';
import { NavigationComponentProps } from 'react-native-navigation';
import { NavigationProps } from 'react-native-navigation';

interface TopBarBackgroundProps extends NavigationComponentProps {
interface TopBarBackgroundProps extends NavigationProps {
color: string;
}

Expand Down
4 changes: 2 additions & 2 deletions playground/src/screens/Alert.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import { StyleSheet, Text, Button, View, ViewStyle, TextStyle } from 'react-native';
import { Navigation, NavigationComponentProps } from 'react-native-navigation';
import { Navigation, NavigationProps } from 'react-native-navigation';
import testIDs from '../testIDs';

interface Props extends NavigationComponentProps {
interface Props extends NavigationProps {
title: string;
message: string;
}
Expand Down
4 changes: 2 additions & 2 deletions playground/src/screens/BackButtonScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { NavigationComponentProps, Options } from 'react-native-navigation';
import { NavigationProps, Options } from 'react-native-navigation';
import Root from '../components/Root';
import Button from '../components/Button';
import Screens from './Screens';
Expand All @@ -17,7 +17,7 @@ const {
BACK_BUTTON,
} = testIDs;

export default class BackButtonScreen extends React.Component<NavigationComponentProps> {
export default class BackButtonScreen extends React.Component<NavigationProps> {
visible: boolean = true;
static options(): Options {
return {
Expand Down
4 changes: 2 additions & 2 deletions playground/src/screens/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {
ViewStyle,
TextStyle,
} from 'react-native';
import { Navigation, NavigationComponentProps } from 'react-native-navigation';
import { Navigation, NavigationProps } from 'react-native-navigation';

interface Props extends NavigationComponentProps {
interface Props extends NavigationProps {
title: string;
accessibilityLabel?: string;
color: string;
Expand Down
4 changes: 2 additions & 2 deletions playground/src/screens/ContextScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import { Text, Button, StyleSheet, ViewStyle, TextStyle } from 'react-native';
import { NavigationComponentProps } from 'react-native-navigation';
import { NavigationProps } from 'react-native-navigation';
import Root from '../components/Root';
import { GlobalContext, Context } from '../context';

export default class ContextScreen extends React.Component<NavigationComponentProps> {
export default class ContextScreen extends React.Component<NavigationProps> {
static contextType = Context;

static options() {
Expand Down
4 changes: 2 additions & 2 deletions playground/src/screens/CustomTextButton.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { StyleSheet, View, TouchableOpacity, Text, Alert } from 'react-native';
import { NavigationComponentProps } from 'react-native-navigation';
import { NavigationProps } from 'react-native-navigation';

interface Props extends NavigationComponentProps {
interface Props extends NavigationProps {
title: string;
}

Expand Down
4 changes: 2 additions & 2 deletions playground/src/screens/CustomTopBar.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { StyleSheet, View, TouchableOpacity, Text, Alert } from 'react-native';
import { NavigationComponentProps } from 'react-native-navigation';
import { NavigationProps } from 'react-native-navigation';

interface Props extends NavigationComponentProps {
interface Props extends NavigationProps {
title: string;
text: string;
clickable: boolean;
Expand Down
4 changes: 2 additions & 2 deletions playground/src/screens/ExternalComponentScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { NavigationComponentProps } from 'react-native-navigation';
import { NavigationProps } from 'react-native-navigation';
import Root from '../components/Root';
import Button from '../components/Button';
import Screens from './Screens';
Expand All @@ -9,7 +9,7 @@ import testIDs from '../testIDs';

const { PUSH_BTN, MODAL_BTN, REGISTER_MODAL_DISMISS_EVENT_BTN } = testIDs;

export default class ExternalComponentScreen extends React.Component<NavigationComponentProps> {
export default class ExternalComponentScreen extends React.Component<NavigationProps> {
static options() {
return {
topBar: {
Expand Down
4 changes: 2 additions & 2 deletions playground/src/screens/FirstBottomTabScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { NavigationComponentProps, Options } from 'react-native-navigation';
import { NavigationProps, Options } from 'react-native-navigation';
import Root from '../components/Root';
import Button from '../components/Button';
import Navigation from './../services/Navigation';
Expand All @@ -18,7 +18,7 @@ const {
FIRST_TAB_BAR_BUTTON,
} = testIDs;

export default class FirstBottomTabScreen extends React.Component<NavigationComponentProps> {
export default class FirstBottomTabScreen extends React.Component<NavigationProps> {
static options(): Options {
return {
layout: {
Expand Down
6 changes: 3 additions & 3 deletions playground/src/screens/FlatListScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { FlatList, View, Text } from 'react-native';
import {
Navigation,
NavigationComponentProps,
NavigationProps,
NavigationButtonPressedEvent,
NavigationComponent,
Options,
Expand All @@ -23,7 +23,7 @@ type FakeDataItem = {
gender: string;
};

export default class FlatListScreen extends NavigationComponent<NavigationComponentProps, State> {
export default class FlatListScreen extends NavigationComponent<NavigationProps, State> {
static options(): Options {
return {
topBar: {
Expand Down Expand Up @@ -63,7 +63,7 @@ export default class FlatListScreen extends NavigationComponent<NavigationCompon
};
}

constructor(props: NavigationComponentProps) {
constructor(props: NavigationProps) {
super(props);
Navigation.events().bindComponent(this);
this.state = { isFetching: false, shouldHideOnScroll: false };
Expand Down
4 changes: 2 additions & 2 deletions playground/src/screens/KeyboardScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { View, ScrollView, Dimensions, StyleSheet, Image, TextInput, Text } from 'react-native';
import {
NavigationComponentProps,
NavigationProps,
NavigationComponent,
ComponentDidAppearEvent,
} from 'react-native-navigation';
Expand All @@ -12,7 +12,7 @@ import testIDs from '../testIDs';
import { stack } from '../commons/Layouts';
const screenWidth = Dimensions.get('window').width;
const KEYBOARD_LABEL = 'Keyboard Demo';
interface Props extends NavigationComponentProps {
interface Props extends NavigationProps {
title?: string;
autoFocus?: boolean;
}
Expand Down
6 changes: 3 additions & 3 deletions playground/src/screens/LayoutsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
Options,
OptionsModalPresentationStyle,
NavigationComponent,
NavigationComponentProps,
NavigationProps,
} from 'react-native-navigation';

import Root from '../components/Root';
Expand All @@ -28,8 +28,8 @@ interface State {
componentDidAppear: boolean;
}

export default class LayoutsScreen extends NavigationComponent<NavigationComponentProps, State> {
constructor(props: NavigationComponentProps) {
export default class LayoutsScreen extends NavigationComponent<NavigationProps, State> {
constructor(props: NavigationProps) {
super(props);
Navigation.events().bindComponent(this);
this.state = {
Expand Down
6 changes: 3 additions & 3 deletions playground/src/screens/LazilyRegisteredScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';
import { NavigationComponentProps, Options } from 'react-native-navigation';
import { NavigationProps, Options } from 'react-native-navigation';
import Root from '../components/Root';
import Button from '../components/Button';
import Navigation from '../services/Navigation';
import testIDs from '../testIDs';
import Screens from './Screens';

class LazilyRegisteredScreen extends React.Component<NavigationComponentProps> {
class LazilyRegisteredScreen extends React.Component<NavigationProps> {
static options(): Options {
return {
topBar: {
Expand All @@ -24,7 +24,7 @@ class LazilyRegisteredScreen extends React.Component<NavigationComponentProps> {
};
}

constructor(props: NavigationComponentProps) {
constructor(props: NavigationProps) {
super(props);
Navigation.events().bindComponent(this);
}
Expand Down
4 changes: 2 additions & 2 deletions playground/src/screens/LazyTopBar.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import { StyleSheet, View, Text } from 'react-native';
import { NavigationComponentProps } from 'react-native-navigation';
import { NavigationProps } from 'react-native-navigation';
import testIDs from '../testIDs';

interface Props extends NavigationComponentProps {
interface Props extends NavigationProps {
title: string;
text: string;
}
Expand Down
4 changes: 2 additions & 2 deletions playground/src/screens/LifecycleScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { NavigationComponentProps, NavigationButtonPressedEvent } from 'react-native-navigation';
import { NavigationProps, NavigationButtonPressedEvent } from 'react-native-navigation';
import Root from '../components/Root';
import Button from '../components/Button';
import Navigation from '../services/Navigation';
Expand All @@ -8,7 +8,7 @@ import testIDs from '../testIDs';

const { PUSH_TO_TEST_DID_DISAPPEAR_BTN, DISMISS_MODAL_BTN, SCREEN_POPPED_BTN, POP_BTN } = testIDs;

interface Props extends NavigationComponentProps {
interface Props extends NavigationProps {
isModal?: boolean;
}

Expand Down
6 changes: 3 additions & 3 deletions playground/src/screens/ModalCommandsScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { Text } from 'react-native';
import { NavigationComponent, NavigationComponentProps } from 'react-native-navigation';
import { NavigationComponent, NavigationProps } from 'react-native-navigation';
import Root from '../components/Root';
import Button from '../components/Button';
import Navigation from '../services/Navigation';
Expand All @@ -21,7 +21,7 @@ interface State {
dismissModalPromiseResult?: string;
}

export default class ModalScreen extends NavigationComponent<NavigationComponentProps, State> {
export default class ModalScreen extends NavigationComponent<NavigationProps, State> {
static options() {
return {
topBar: {
Expand All @@ -32,7 +32,7 @@ export default class ModalScreen extends NavigationComponent<NavigationComponent
};
}

constructor(props: NavigationComponentProps) {
constructor(props: NavigationProps) {
super(props);
Navigation.events().registerModalDismissedListener(({ componentId }) => {
this.setState({
Expand Down
4 changes: 2 additions & 2 deletions playground/src/screens/NavigationScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { Platform } from 'react-native';
import {
NavigationComponent,
NavigationComponentProps,
NavigationProps,
OptionsModalPresentationStyle,
} from 'react-native-navigation';
import Root from '../components/Root';
Expand All @@ -24,7 +24,7 @@ const {
BACK_BUTTON_SCREEN_BTN,
} = testIDs;

interface Props extends NavigationComponentProps {}
interface Props extends NavigationProps {}

export default class NavigationScreen extends NavigationComponent<Props> {
static options() {
Expand Down
4 changes: 2 additions & 2 deletions playground/src/screens/OptionsScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { NavigationComponent, NavigationComponentProps } from 'react-native-navigation';
import { NavigationComponent, NavigationProps } from 'react-native-navigation';
import Button from '../components/Button';
import Root from '../components/Root';
import Navigation from '../services/Navigation';
Expand All @@ -22,7 +22,7 @@ const {
REPLACED_TAB,
} = testIDs;

interface Props extends NavigationComponentProps {}
interface Props extends NavigationProps {}

export default class Options extends NavigationComponent<Props> {
static options() {
Expand Down
4 changes: 2 additions & 2 deletions playground/src/screens/OrientationDetectScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import {
} from 'react-native';
import {
Navigation,
NavigationComponentProps,
NavigationProps,
LayoutOrientation,
NavigationComponent,
Options,
} from 'react-native-navigation';
import TestIDs from '../testIDs';

interface Props extends NavigationComponentProps {
interface Props extends NavigationProps {
orientation: LayoutOrientation[]; // LayoutOrientation type is not exposed.
}

Expand Down
4 changes: 2 additions & 2 deletions playground/src/screens/OrientationScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Navigation, NavigationComponentProps, LayoutOrientation } from 'react-native-navigation';
import { Navigation, NavigationProps, LayoutOrientation } from 'react-native-navigation';
import Root from '../components/Root';
import Button from '../components/Button';
import Screens from './Screens';
Expand All @@ -11,7 +11,7 @@ const {
PORTRAIT_ORIENTATION_BTN,
} = testIDs;

export default class OrientationScreen extends React.Component<NavigationComponentProps> {
export default class OrientationScreen extends React.Component<NavigationProps> {
render() {
return (
<Root componentId={this.props.componentId}>
Expand Down
Loading

0 comments on commit 39e3cb1

Please sign in to comment.