Remove Button error boundary (#3372)
parent
75c9da931c
commit
75d6535402
|
@ -14,7 +14,6 @@ import {
|
||||||
import LinearGradient from 'react-native-linear-gradient'
|
import LinearGradient from 'react-native-linear-gradient'
|
||||||
import {Trans} from '@lingui/macro'
|
import {Trans} from '@lingui/macro'
|
||||||
|
|
||||||
import {logger} from '#/logger'
|
|
||||||
import {android, atoms as a, flatten, tokens, useTheme} from '#/alf'
|
import {android, atoms as a, flatten, tokens, useTheme} from '#/alf'
|
||||||
import {Props as SVGIconProps} from '#/components/icons/common'
|
import {Props as SVGIconProps} from '#/components/icons/common'
|
||||||
import {normalizeTextStyles} from '#/components/Typography'
|
import {normalizeTextStyles} from '#/components/Typography'
|
||||||
|
@ -405,51 +404,20 @@ export function Button({
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
<Context.Provider value={context}>
|
<Context.Provider value={context}>
|
||||||
<ButtonTextErrorBoundary>
|
{/* @ts-ignore */}
|
||||||
{/* @ts-ignore */}
|
{typeof children === 'string' || children?.type === Trans ? (
|
||||||
{typeof children === 'string' || children?.type === Trans ? (
|
/* @ts-ignore */
|
||||||
/* @ts-ignore */
|
<ButtonText>{children}</ButtonText>
|
||||||
<ButtonText>{children}</ButtonText>
|
) : typeof children === 'function' ? (
|
||||||
) : typeof children === 'function' ? (
|
children(context)
|
||||||
children(context)
|
) : (
|
||||||
) : (
|
children
|
||||||
children
|
)}
|
||||||
)}
|
|
||||||
</ButtonTextErrorBoundary>
|
|
||||||
</Context.Provider>
|
</Context.Provider>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ButtonTextErrorBoundary extends React.Component<
|
|
||||||
React.PropsWithChildren<{}>,
|
|
||||||
{hasError: boolean; error: Error | undefined}
|
|
||||||
> {
|
|
||||||
public state = {
|
|
||||||
hasError: false,
|
|
||||||
error: undefined,
|
|
||||||
}
|
|
||||||
|
|
||||||
public static getDerivedStateFromError(error: Error) {
|
|
||||||
return {hasError: true, error}
|
|
||||||
}
|
|
||||||
|
|
||||||
public componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
|
|
||||||
logger.error('ButtonTextErrorBoundary caught an error', {
|
|
||||||
message: error.message,
|
|
||||||
errorInfo,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
public render() {
|
|
||||||
if (this.state.hasError) {
|
|
||||||
return <ButtonText>ERROR</ButtonText>
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.props.children
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useSharedButtonTextStyles() {
|
export function useSharedButtonTextStyles() {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {color, variant, disabled, size} = useButtonContext()
|
const {color, variant, disabled, size} = useButtonContext()
|
||||||
|
|
Loading…
Reference in New Issue