Skip to content

Commit

Permalink
- 处理了收集到的崩溃问题
Browse files Browse the repository at this point in the history
  • Loading branch information
czy0729 committed Jul 22, 2024
1 parent 9dc99a2 commit 9d92abe
Show file tree
Hide file tree
Showing 20 changed files with 137 additions and 109 deletions.
4 changes: 2 additions & 2 deletions app.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"expo": {
"description": "A React Native App for https://bgm.tv, tinygrail plugin 5.1.0",
"version": "8.12.0",
"version": "8.12.1",
"android": {
"versionCode": 89500,
"versionCode": 812000,
"package": "com.czy0729.bangumi",
"adaptiveIcon": {
"foregroundImage": "./src/assets/images/foreground.png",
Expand Down
6 changes: 4 additions & 2 deletions src/components/@/react-native-modal-popover/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @Author: czy0729
* @Date: 2024-03-08 19:29:51
* @Last Modified by: czy0729
* @Last Modified time: 2024-03-08 19:34:38
* @Last Modified time: 2024-07-22 16:32:45
*/
import * as React from 'react'
import {
Expand Down Expand Up @@ -184,7 +184,9 @@ export class Popover extends React.PureComponent<PopoverProps, PopoverState> {
}

componentWillUnmount() {
this.dimensionsSub?.remove()
try {
this.dimensionsSub?.remove()
} catch (error) {}
}

private computeGeometry = (props: PopoverProps, contentSize: Size): Geometry =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @Author: czy0729
* @Date: 2024-03-08 19:29:55
* @Last Modified by: czy0729
* @Last Modified time: 2024-03-08 19:34:56
* @Last Modified time: 2024-07-22 16:32:54
*/
import * as React from 'react'
import {
Expand Down Expand Up @@ -53,7 +53,9 @@ export class PopoverController extends React.PureComponent<Props, State> {
}

componentWillUnmount() {
this.dimensionsSub?.remove()
try {
this.dimensionsSub?.remove()
} catch (error) {}
}

private onOrientationChange = () => {
Expand Down
41 changes: 19 additions & 22 deletions src/components/@/react-native-tab-view/SceneView.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as React from 'react'
import { View, StyleSheet, StyleProp, ViewStyle } from 'react-native'
import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native'
import {
SceneRendererProps,
EventEmitterProps,
NavigationState,
Route
Route,
SceneRendererProps
} from 'react-native-tab-view/src/types'
import { stl } from '@utils'

Expand All @@ -22,10 +22,7 @@ type State = {
loading: boolean
}

export default class SceneView<T extends Route> extends React.Component<
Props<T>,
State
> {
export default class SceneView<T extends Route> extends React.Component<Props<T>, State> {
static getDerivedStateFromProps(props: Props<Route>, state: State) {
if (
state.loading &&
Expand All @@ -40,14 +37,15 @@ export default class SceneView<T extends Route> extends React.Component<

state = {
loading:
Math.abs(this.props.navigationState.index - this.props.index) >
this.props.lazyPreloadDistance
Math.abs(this.props.navigationState.index - this.props.index) > this.props.lazyPreloadDistance
}

componentDidMount() {
if (this.props.lazy) {
// If lazy mode is enabled, listen to when we enter screens
this.props.addListener('enter', this.handleEnter)
try {
this.props.addListener('enter', this.handleEnter)
} catch (error) {}
} else if (this.state.loading) {
// If lazy mode is not enabled, render the scene with a delay if not loaded already
// This improves the initial startup time as the scene is no longer blocking
Expand All @@ -56,21 +54,24 @@ export default class SceneView<T extends Route> extends React.Component<
}

componentDidUpdate(prevProps: Props<T>, prevState: State) {
if (
this.props.lazy !== prevProps.lazy ||
this.state.loading !== prevState.loading
) {
if (this.props.lazy !== prevProps.lazy || this.state.loading !== prevState.loading) {
// We only need the listener if the tab hasn't loaded yet and lazy is enabled
if (this.props.lazy && this.state.loading) {
this.props.addListener('enter', this.handleEnter)
try {
this.props.addListener('enter', this.handleEnter)
} catch (error) {}
} else {
this.props.removeListener('enter', this.handleEnter)
try {
this.props.removeListener('enter', this.handleEnter)
} catch (error) {}
}
}
}

componentWillUnmount() {
this.props.removeListener('enter', this.handleEnter)
try {
this.props.removeListener('enter', this.handleEnter)
} catch (error) {}
}

private handleEnter = (value: number) => {
Expand All @@ -96,11 +97,7 @@ export default class SceneView<T extends Route> extends React.Component<
styles.route,
// If we don't have the layout yet, make the focused screen fill the container
// This avoids delay before we are able to render pages side by side
layout.width
? { width: layout.width }
: focused
? StyleSheet.absoluteFill
: null,
layout.width ? { width: layout.width } : focused ? StyleSheet.absoluteFill : null,
style
)}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export default function withDimensions(WrappedComponent) {
}

componentWillUnmount() {
Dimensions.removeEventListener('change', this.handleOrientationChange)
try {
Dimensions.removeEventListener('change', this.handleOrientationChange)
} catch (error) {}
}

handleOrientationChange = ({ window }) => {
Expand Down
25 changes: 11 additions & 14 deletions src/components/@/react-navigation/createAppContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ export default function createNavigationContainer(Component) {
}

_renderLoading() {
return this.props.renderLoadingExperimental
? this.props.renderLoadingExperimental()
: null
return this.props.renderLoadingExperimental ? this.props.renderLoadingExperimental() : null
}

_isStateful() {
Expand All @@ -120,9 +118,7 @@ export default function createNavigationContainer(Component) {
if (keys.length !== 0) {
throw new Error(
'This navigator has both navigation and container props, so it is ' +
`unclear if it should own its own state. Remove props: "${keys.join(
', '
)}" ` +
`unclear if it should own its own state. Remove props: "${keys.join(', ')}" ` +
'if the navigator should get its state from the navigation prop. If the ' +
'navigator should maintain its own state, do not pass a navigation prop.'
)
Expand Down Expand Up @@ -205,8 +201,7 @@ export default function createNavigationContainer(Component) {
let parsedUrl = null
let startupStateJSON = null
if (enableURLHandling !== false) {
startupStateJSON =
persistenceKey && (await AsyncStorage.getItem(persistenceKey))
startupStateJSON = persistenceKey && (await AsyncStorage.getItem(persistenceKey))
const url = await Linking.getInitialURL()
parsedUrl = url && urlToPathAndParams(url, uriPrefix)
}
Expand Down Expand Up @@ -287,13 +282,15 @@ export default function createNavigationContainer(Component) {
}

componentWillUnmount() {
this._isMounted = false
Linking.removeEventListener('url', this._handleOpenURL)
this.subs && this.subs.remove()
try {
this._isMounted = false
Linking.removeEventListener('url', this._handleOpenURL)
this.subs && this.subs.remove()

if (this._isStateful()) {
_statefulContainerCount--
}
if (this._isStateful()) {
_statefulContainerCount--
}
} catch (error) {}
}

// Per-tick temporary storage for state.nav
Expand Down
6 changes: 4 additions & 2 deletions src/components/image/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: czy0729
* @Date: 2019-03-15 06:17:18
* @Last Modified by: czy0729
* @Last Modified time: 2024-05-15 12:37:06
* @Last Modified time: 2024-07-22 16:33:32
*/
import React from 'react'
import { Image as RNImage } from 'react-native'
Expand Down Expand Up @@ -158,7 +158,9 @@ export const Image = observer(
}

componentWillUnmount() {
if (this._timeoutId) clearTimeout(this._timeoutId)
try {
if (this._timeoutId) clearTimeout(this._timeoutId)
} catch (error) {}
}

/** 若图片已明确知道在本地有缓存, 忽略大部分预置规则, 直接取出渲染 */
Expand Down
8 changes: 5 additions & 3 deletions src/components/input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: czy0729
* @Date: 2019-03-19 01:43:43
* @Last Modified by: czy0729
* @Last Modified time: 2024-01-14 16:35:30
* @Last Modified time: 2024-07-22 16:33:46
*/
import React from 'react'
import {
Expand Down Expand Up @@ -82,8 +82,10 @@ export const Input = observer(
}

componentWillUnmount() {
if (this.keyboardDidShowListener) this.keyboardDidShowListener.remove()
if (this.keyboardDidHideListener) this.keyboardDidHideListener.remove()
try {
if (this.keyboardDidShowListener) this.keyboardDidShowListener.remove()
if (this.keyboardDidHideListener) this.keyboardDidHideListener.remove()
} catch (error) {}
}

UNSAFE_componentWillReceiveProps({ value }) {
Expand Down
6 changes: 4 additions & 2 deletions src/components/keyboard-spacer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: czy0729
* @Date: 2019-06-13 00:04:53
* @Last Modified by: czy0729
* @Last Modified time: 2024-01-14 16:44:40
* @Last Modified time: 2024-07-22 16:33:57
*/
import React, { Component } from 'react'
import { Dimensions, Keyboard, LayoutAnimation, UIManager, View } from 'react-native'
Expand Down Expand Up @@ -47,7 +47,9 @@ export const KeyboardSpacer = class KeyboardSpacerComponent extends Component<Ke
}

componentWillUnmount() {
this._listeners.forEach(listener => listener.remove())
try {
this._listeners.forEach(listener => listener.remove())
} catch (error) {}
}

updateKeyboardSpace = event => {
Expand Down
14 changes: 8 additions & 6 deletions src/components/toast/container/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: czy0729
* @Date: 2020-09-28 18:30:52
* @Last Modified by: czy0729
* @Last Modified time: 2024-07-09 09:01:21
* @Last Modified time: 2024-07-22 16:34:04
*/
import React from 'react'
import { ActivityIndicator, Animated, TouchableOpacity, View } from 'react-native'
Expand Down Expand Up @@ -76,12 +76,14 @@ export default class Container extends React.Component<ToastProps, any> {
}

componentWillUnmount() {
if (this.timeoutId) clearTimeout(this.timeoutId)
try {
if (this.timeoutId) clearTimeout(this.timeoutId)

if (this.anim) {
this.anim.stop()
this.anim = null
}
if (this.anim) {
this.anim.stop()
this.anim = null
}
} catch (error) {}
}

render() {
Expand Down
12 changes: 7 additions & 5 deletions src/screens/_/base/folder-manage-modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: czy0729
* @Date: 2021-05-27 14:20:46
* @Last Modified by: czy0729
* @Last Modified time: 2024-01-14 03:15:39
* @Last Modified time: 2024-07-22 16:34:16
*/
import React from 'react'
import { BackHandler, ScrollView, View } from 'react-native'
Expand Down Expand Up @@ -107,10 +107,12 @@ export const FolderManageModal = ob(
}

componentWillUnmount() {
this.setState({
visible: false
})
BackHandler.removeEventListener('hardwareBackPress', this.onBackAndroid)
try {
this.setState({
visible: false
})
BackHandler.removeEventListener('hardwareBackPress', this.onBackAndroid)
} catch (error) {}
}

onBackAndroid = () => {
Expand Down
6 changes: 4 additions & 2 deletions src/screens/_/base/listen-clipboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: czy0729
* @Date: 2020-03-11 11:32:31
* @Last Modified by: czy0729
* @Last Modified time: 2024-01-14 03:27:03
* @Last Modified time: 2024-07-22 16:34:30
*/
import React from 'react'
import { AppState, AppStateStatus, Clipboard, NativeEventSubscription } from 'react-native'
Expand Down Expand Up @@ -35,7 +35,9 @@ export const ListenClipboard = class ListenClipboardComponent extends React.Comp
componentWillUnmount() {
if (IOS || STORYBOOK) return

this.appStateListener.remove()
try {
this.appStateListener.remove()
} catch (error) {}
}

onAppStateChange = (nextAppState: AppStateStatus) => {
Expand Down
6 changes: 4 additions & 2 deletions src/screens/_/base/manage-modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: czy0729
* @Date: 2019-03-18 05:01:50
* @Last Modified by: czy0729
* @Last Modified time: 2024-06-23 21:18:20
* @Last Modified time: 2024-07-22 16:34:39
*/
import React from 'react'
import { BackHandler, View } from 'react-native'
Expand Down Expand Up @@ -84,7 +84,9 @@ export const ManageModal = ob(
}

componentWillUnmount() {
if (!IOS) BackHandler.removeEventListener('hardwareBackPress', this.onBackAndroid)
try {
if (!IOS) BackHandler.removeEventListener('hardwareBackPress', this.onBackAndroid)
} catch (error) {}
}

async UNSAFE_componentWillReceiveProps(nextProps: {
Expand Down
8 changes: 4 additions & 4 deletions src/screens/tinygrail/_/characters-modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: czy0729
* @Date: 2020-06-28 14:02:31
* @Last Modified by: czy0729
* @Last Modified time: 2024-05-21 19:42:47
* @Last Modified time: 2024-07-22 16:36:08
*/
import React from 'react'
import { BackHandler, View } from 'react-native'
Expand Down Expand Up @@ -76,7 +76,9 @@ class CharactersModal extends React.Component<Props> {
}

componentWillUnmount() {
BackHandler.removeEventListener('hardwareBackPress', this.onBackAndroid)
try {
BackHandler.removeEventListener('hardwareBackPress', this.onBackAndroid)
} catch (error) {}
}

UNSAFE_componentWillReceiveProps(nextProps: {
Expand All @@ -95,8 +97,6 @@ class CharactersModal extends React.Component<Props> {
})
this.title = nextProps.title
}

// if (!IOS) StatusBar.setHidden(nextProps.visible)
}

onBackAndroid = () => {
Expand Down
Loading

0 comments on commit 9d92abe

Please sign in to comment.