Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mobile: Resolves #7687: Use .remove instead of removeEventListener #7688

Merged
merged 4 commits into from Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/app-mobile/components/screens/ConfigScreen.tsx
Expand Up @@ -577,7 +577,7 @@ class ConfigScreenComponent extends BaseScreenComponent {
<Text key="label" style={this.styles().settingText}>
{md.label()}
</Text>
<TextInput autoCorrect={false} autoCompleteType="off" selectionColor={theme.textSelectionColor} keyboardAppearance={theme.keyboardAppearance} autoCapitalize="none" key="control" style={this.styles().settingControl} value={value} onChangeText={(value: any) => updateSettingValue(key, value)} secureTextEntry={!!md.secure} />
<TextInput autoCorrect={false} autoComplete="off" selectionColor={theme.textSelectionColor} keyboardAppearance={theme.keyboardAppearance} autoCapitalize="none" key="control" style={this.styles().settingControl} value={value} onChangeText={(value: any) => updateSettingValue(key, value)} secureTextEntry={!!md.secure} />
laurent22 marked this conversation as resolved.
Show resolved Hide resolved
</View>
);
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/app-mobile/package.json
Expand Up @@ -95,7 +95,7 @@
"@lezer/highlight": "1.1.3",
"@types/fs-extra": "9.0.13",
"@types/jest": "29.2.6",
"@types/react-native": "0.64.19",
"@types/react-native": "0.70.6",
"@types/react-redux": "7.1.25",
"babel-plugin-module-resolver": "4.1.0",
"execa": "4.1.0",
Expand Down
22 changes: 16 additions & 6 deletions packages/app-mobile/root.tsx
Expand Up @@ -28,8 +28,8 @@ import SyncTargetJoplinCloud from '@joplin/lib/SyncTargetJoplinCloud';
import SyncTargetOneDrive from '@joplin/lib/SyncTargetOneDrive';
import initProfile from '@joplin/lib/services/profileConfig/initProfile';
const VersionInfo = require('react-native-version-info').default;
const { Keyboard, NativeModules, BackHandler, Animated, View, StatusBar, Linking, Platform, Dimensions } = require('react-native');
const RNAppState = require('react-native').AppState;
const { Keyboard, NativeModules, BackHandler, Animated, View, StatusBar, Platform, Dimensions } = require('react-native');
import { AppState as RNAppState, EmitterSubscription, Linking, NativeEventSubscription } from 'react-native';
import getResponsiveValue from './components/getResponsiveValue';
import NetInfo from '@react-native-community/netinfo';
const DropdownAlert = require('react-native-dropdownalert').default;
Expand Down Expand Up @@ -704,6 +704,9 @@ async function initialize(dispatch: Function) {

class AppComponent extends React.Component {

private urlOpenListener_: EmitterSubscription|null = null;
private appStateChangeListener_: NativeEventSubscription|null = null;

public constructor() {
super();

Expand Down Expand Up @@ -796,7 +799,7 @@ class AppComponent extends React.Component {
// }, 1000);
}

Linking.addEventListener('url', this.handleOpenURL_);
this.urlOpenListener_ = Linking.addEventListener('url', this.handleOpenURL_);

BackButtonService.initialize(this.backButtonHandler_);

Expand All @@ -806,7 +809,7 @@ class AppComponent extends React.Component {
this.dropdownAlert_.alertWithType('info', notification.title, notification.body ? notification.body : '');
});

RNAppState.addEventListener('change', this.onAppStateChange_);
this.appStateChangeListener_ = RNAppState.addEventListener('change', this.onAppStateChange_);
this.unsubscribeScreenWidthChangeHandler_ = Dimensions.addEventListener('change', this.handleScreenWidthChange_);

await this.handleShareData();
Expand All @@ -820,8 +823,15 @@ class AppComponent extends React.Component {
}

public componentWillUnmount() {
RNAppState.removeEventListener('change', this.onAppStateChange_);
Linking.removeEventListener('url', this.handleOpenURL_);
if (this.appStateChangeListener_) {
this.appStateChangeListener_.remove();
this.appStateChangeListener_ = null;
}

if (this.urlOpenListener_) {
this.urlOpenListener_.remove();
this.urlOpenListener_ = null;
}

if (this.unsubscribeScreenWidthChangeHandler_) {
this.unsubscribeScreenWidthChangeHandler_.remove();
Expand Down
11 changes: 10 additions & 1 deletion yarn.lock
Expand Up @@ -4712,7 +4712,7 @@ __metadata:
"@react-native-community/slider": 4.4.1
"@types/fs-extra": 9.0.13
"@types/jest": 29.2.6
"@types/react-native": 0.64.19
"@types/react-native": 0.70.6
"@types/react-redux": 7.1.25
assert-browserify: 2.0.0
babel-plugin-module-resolver: 4.1.0
Expand Down Expand Up @@ -7710,6 +7710,15 @@ __metadata:
languageName: node
linkType: hard

"@types/react-native@npm:0.70.6":
version: 0.70.6
resolution: "@types/react-native@npm:0.70.6"
dependencies:
"@types/react": "*"
checksum: 1b620095ddf2fe85157df9d57435edc619587eacb1a4fadd91c977c200cef8008e7fec4d8c5429ce373e1a2158199f1162f9c84e8e5a7d0b71a2224f31b64dfd
languageName: node
linkType: hard

"@types/react-redux@npm:7.1.25":
version: 7.1.25
resolution: "@types/react-redux@npm:7.1.25"
Expand Down