Skip to content

Commit

Permalink
components/Header: add onBack prop for extra functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloudis committed Apr 1, 2023
1 parent f57911f commit 359f118
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
28 changes: 18 additions & 10 deletions components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,29 @@ interface HeaderProps {
containerStyle?: any;
placement?: 'left' | 'center' | 'right' | undefined;
navigation?: any;
onBack?: () => void;
}

function ZeusHeader(props: HeaderProps) {
const BackButton = () => (
const BackButton = (onBack?: () => void) => (
<Icon
name="arrow-back"
onPress={() => props.navigation.goBack()}
onPress={() => {
if (onBack) onBack();
props.navigation.goBack();
}}
color={themeColor('text')}
underlayColor="transparent"
/>
);

const CloseButton = () => (
const CloseButton = (onBack?: () => void) => (
<Icon
name="close"
onPress={() => props.navigation.goBack()}
onPress={() => {
if (onBack) onBack();
props.navigation.goBack();
}}
color={themeColor('text')}
underlayColor="transparent"
/>
Expand All @@ -35,21 +42,22 @@ function ZeusHeader(props: HeaderProps) {
centerComponent,
rightComponent,
containerStyle,
placement
placement,
onBack
} = props;
return (
<Header
leftComponent={
leftComponent === 'Back'
? BackButton
? BackButton(onBack)
: leftComponent === 'Close'
? CloseButton
? CloseButton(onBack)
: leftComponent
? leftComponent
: null
: undefined
}
centerComponent={centerComponent ? centerComponent : null}
rightComponent={rightComponent ? rightComponent : null}
centerComponent={centerComponent ? centerComponent : undefined}
rightComponent={rightComponent ? rightComponent : undefined}
backgroundColor="transparent"
containerStyle={{
...containerStyle,
Expand Down
12 changes: 5 additions & 7 deletions views/Receive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,19 +226,15 @@ export default class Receive extends React.Component<
if (this.onChainInterval) clearInterval(this.onChainInterval);
};

navBack = () => {
const { InvoicesStore, navigation } = this.props;
onBack = () => {
const { InvoicesStore } = this.props;
const { reset } = InvoicesStore;
// kill all listeners and pollers before navigating back
this.clearListeners();
this.clearIntervals();

// clear invoice
reset();

navigation.navigate('Wallet', {
refresh: true
});
};

autoGenerateInvoice = (
Expand Down Expand Up @@ -825,7 +821,8 @@ export default class Receive extends React.Component<
return (
<Screen>
<Header
leftComponent={<BackButton />}
leftComponent="Back"
onBack={this.onBack}
centerComponent={{
text:
posStatus === 'active'
Expand All @@ -847,6 +844,7 @@ export default class Receive extends React.Component<
)
)
}
navigation={navigation}
/>

<ScrollView style={styles.content}>
Expand Down

0 comments on commit 359f118

Please sign in to comment.