Skip to content

Commit

Permalink
Chore: Migrate react-navigation to TypeScript (#3480)
Browse files Browse the repository at this point in the history
Co-authored-by: AlexAlexandre <alexalexandrejr@gmail.com>
  • Loading branch information
gerzonc and AlexAlexandre authored Dec 3, 2021
1 parent 4af97f1 commit 691bf1e
Show file tree
Hide file tree
Showing 64 changed files with 901 additions and 373 deletions.
5 changes: 3 additions & 2 deletions app/AppContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import { connect } from 'react-redux';

import { SetUsernameStackParamList, StackParamList } from './navigationTypes';
import Navigation from './lib/Navigation';
import { defaultHeader, getActiveRouteName, navigationTheme } from './utils/navigation';
import { ROOT_INSIDE, ROOT_LOADING, ROOT_OUTSIDE, ROOT_SET_USERNAME } from './actions/app';
Expand All @@ -17,15 +18,15 @@ import { ThemeContext } from './theme';
import { setCurrentScreen } from './utils/log';

// SetUsernameStack
const SetUsername = createStackNavigator();
const SetUsername = createStackNavigator<SetUsernameStackParamList>();
const SetUsernameStack = () => (
<SetUsername.Navigator screenOptions={defaultHeader}>
<SetUsername.Screen name='SetUsernameView' component={SetUsernameView} />
</SetUsername.Navigator>
);

// App
const Stack = createStackNavigator();
const Stack = createStackNavigator<StackParamList>();
const App = React.memo(({ root, isMasterDetail }: { root: string; isMasterDetail: boolean }) => {
if (!root) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion app/containers/ActionSheet/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const useActionSheet = () => useContext(context);

const { Provider, Consumer } = context;

export const withActionSheet = <P extends object>(Component: React.ComponentType<P>) =>
export const withActionSheet = (Component: any): any =>
forwardRef((props: any, ref: ForwardedRef<any>) => (
<Consumer>{(contexts: any) => <Component {...props} {...contexts} ref={ref} />}</Consumer>
));
Expand Down
5 changes: 3 additions & 2 deletions app/containers/EmojiPicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface IEmojiPickerProps {
customEmojis?: any;
style: object;
theme?: string;
onEmojiSelected?: Function;
onEmojiSelected?: ((emoji: any) => void) | ((keyboardId: any, params?: any) => void);
tabEmojiStyle?: object;
}

Expand Down Expand Up @@ -201,4 +201,5 @@ const mapStateToProps = (state: any) => ({
customEmojis: state.customEmojis
});

export default connect(mapStateToProps)(withTheme(EmojiPicker));
// TODO - remove this as any, at the new PR to fix the HOC erros
export default connect(mapStateToProps)(withTheme(EmojiPicker)) as any;
2 changes: 1 addition & 1 deletion app/containers/LoginServices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -423,4 +423,4 @@ const mapStateToProps = (state: any) => ({
services: state.login.services
});

export default connect(mapStateToProps)(withTheme(LoginServices));
export default connect(mapStateToProps)(withTheme(LoginServices)) as any;
2 changes: 1 addition & 1 deletion app/containers/MessageBox/EmojiKeyboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface IMessageBoxEmojiKeyboard {
}

export default class EmojiKeyboard extends React.PureComponent<IMessageBoxEmojiKeyboard, any> {
private readonly baseUrl: any;
private readonly baseUrl: string;

constructor(props: IMessageBoxEmojiKeyboard) {
super(props);
Expand Down
2 changes: 1 addition & 1 deletion app/containers/MessageBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1124,4 +1124,4 @@ const dispatchToProps = {
typing: (rid: any, status: any) => userTypingAction(rid, status)
};
// @ts-ignore
export default connect(mapStateToProps, dispatchToProps, null, { forwardRef: true })(withActionSheet(MessageBox));
export default connect(mapStateToProps, dispatchToProps, null, { forwardRef: true })(withActionSheet(MessageBox)) as any;
4 changes: 2 additions & 2 deletions app/containers/SearchBox.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { StyleSheet, Text, TextInputProps, View } from 'react-native';
import Touchable from 'react-native-platform-touchable';

import TextInput from '../presentation/TextInput';
Expand Down Expand Up @@ -45,7 +45,7 @@ const styles = StyleSheet.create({
});

interface ISearchBox {
onChangeText: () => void;
onChangeText: TextInputProps['onChangeText'];
onSubmitEditing: () => void;
hasCancel: boolean;
onCancelPress: Function;
Expand Down
10 changes: 10 additions & 0 deletions app/definitions/IAttachment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface IAttachment {
title: string;
type: string;
description: string;
title_link?: string;
image_url?: string;
image_type?: string;
video_url?: string;
video_type?: string;
}
3 changes: 3 additions & 0 deletions app/definitions/IMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface IMessage {
msg: string;
}
4 changes: 4 additions & 0 deletions app/definitions/IRocketChatRecord.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface IRocketChatRecord {
id: string;
updatedAt: Date;
}
27 changes: 27 additions & 0 deletions app/definitions/IRoom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { IRocketChatRecord } from './IRocketChatRecord';

export enum RoomType {
GROUP = 'p',
DIRECT = 'd',
CHANNEL = 'c',
OMNICHANNEL = 'l',
THREAD = 'thread'
}

export interface IRoom extends IRocketChatRecord {
rid: string;
t: RoomType;
name: string;
fname: string;
prid?: string;
tmid?: string;
topic?: string;
teamMain?: boolean;
teamId?: string;
encrypted?: boolean;
visitor?: boolean;
autoTranslateLanguage?: boolean;
autoTranslate?: boolean;
observe?: Function;
usedCannedResponse: string;
}
16 changes: 16 additions & 0 deletions app/definitions/IServer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export interface IServer {
name: string;
iconURL: string;
useRealName: boolean;
FileUpload_MediaTypeWhiteList: string;
FileUpload_MaxFileSize: number;
roomsUpdatedAt: Date;
version: string;
lastLocalAuthenticatedSession: Date;
autoLock: boolean;
autoLockTime: number | null;
biometry: boolean | null;
uniqueID: string;
enterpriseModules: string;
E2E_Enable: boolean;
}
File renamed without changes.
2 changes: 1 addition & 1 deletion app/dimensions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface IDimensionsContextProps {

export const DimensionsContext = React.createContext<Partial<IDimensionsContextProps>>(Dimensions.get('window'));

export function withDimensions(Component: any) {
export function withDimensions(Component: any): any {
const DimensionsComponent = (props: any) => (
<DimensionsContext.Consumer>{contexts => <Component {...props} {...contexts} />}</DimensionsContext.Consumer>
);
Expand Down
1 change: 1 addition & 0 deletions app/ee/omnichannel/views/QueueListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,5 @@ const mapStateToProps = state => ({
showAvatar: state.sortPreferences.showAvatar,
displayMode: state.sortPreferences.displayMode
});

export default connect(mapStateToProps)(withDimensions(withTheme(QueueListView)));
2 changes: 1 addition & 1 deletion app/lib/rocketchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { selectServerFailure } from '../actions/server';
import { useSsl } from '../utils/url';
import EventEmitter from '../utils/events';
import { updatePermission } from '../actions/permissions';
import { TEAM_TYPE } from '../definition/ITeam';
import { TEAM_TYPE } from '../definitions/ITeam';
import { updateSettings } from '../actions/settings';
import { compareServerVersion, methods } from './utils';
import reduxStore from './createStore';
Expand Down
45 changes: 45 additions & 0 deletions app/navigationTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { NavigatorScreenParams } from '@react-navigation/core';

import { IRoom } from './definitions/IRoom';
import { IServer } from './definitions/IServer';
import { IAttachment } from './definitions/IAttachment';
import { MasterDetailInsideStackParamList } from './stacks/MasterDetailStack/types';
import { OutsideParamList, InsideStackParamList } from './stacks/types';

export type SetUsernameStackParamList = {
SetUsernameView: {
title: string;
};
};

export type StackParamList = {
AuthLoading: undefined;
OutsideStack: NavigatorScreenParams<OutsideParamList>;
InsideStack: NavigatorScreenParams<InsideStackParamList>;
MasterDetailStack: NavigatorScreenParams<MasterDetailInsideStackParamList>;
SetUsernameStack: NavigatorScreenParams<SetUsernameStackParamList>;
};

export type ShareInsideStackParamList = {
ShareListView: undefined;
ShareView: {
attachments: IAttachment[];
isShareView?: boolean;
isShareExtension: boolean;
serverInfo: IServer;
text: string;
room: IRoom;
thread: any; // TODO: Change
};
SelectServerView: undefined;
};

export type ShareOutsideStackParamList = {
WithoutServersView: undefined;
};

export type ShareAppStackParamList = {
AuthLoading?: undefined;
OutsideStack?: NavigatorScreenParams<ShareOutsideStackParamList>;
InsideStack?: NavigatorScreenParams<ShareInsideStackParamList>;
};
16 changes: 6 additions & 10 deletions app/share.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { setCurrentScreen } from './utils/log';
import AuthLoadingView from './views/AuthLoadingView';
import { DimensionsContext } from './dimensions';
import debounce from './utils/debounce';
import { ShareInsideStackParamList, ShareOutsideStackParamList, ShareAppStackParamList } from './navigationTypes';

interface IDimensions {
width: number;
Expand All @@ -46,7 +47,7 @@ interface IState {
fontScale: number;
}

const Inside = createStackNavigator();
const Inside = createStackNavigator<ShareInsideStackParamList>();
const InsideStack = () => {
const { theme } = useContext(ThemeContext);

Expand All @@ -65,24 +66,19 @@ const InsideStack = () => {
);
};

const Outside = createStackNavigator();
const Outside = createStackNavigator<ShareOutsideStackParamList>();
const OutsideStack = () => {
const { theme } = useContext(ThemeContext);

return (
<Outside.Navigator screenOptions={{ ...defaultHeader, ...themedHeader(theme) }}>
<Outside.Screen
name='WithoutServersView'
component={WithoutServersView}
/* @ts-ignore*/
options={WithoutServersView.navigationOptions}
/>
<Outside.Screen name='WithoutServersView' component={WithoutServersView} options={WithoutServersView.navigationOptions} />
</Outside.Navigator>
);
};

// App
const Stack = createStackNavigator();
const Stack = createStackNavigator<ShareAppStackParamList>();
export const App = ({ root }: any) => (
<Stack.Navigator screenOptions={{ headerShown: false, animationEnabled: false }}>
<>
Expand Down Expand Up @@ -112,7 +108,7 @@ class Root extends React.Component<{}, IState> {
this.init();
}

componentWillUnmount() {
componentWillUnmount(): void {
RocketChat.closeShareExtension();
unsubscribeTheme();
}
Expand Down
Loading

0 comments on commit 691bf1e

Please sign in to comment.