Skip to content

Commit

Permalink
Merge pull request #41664 from hungvu193/feat/update-connection-layout
Browse files Browse the repository at this point in the history
Add ability to use View in ConnectionLayout
  • Loading branch information
lakchote authored May 7, 2024
2 parents 84118d8 + 2cf4bc4 commit 23297de
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions src/components/ConnectionLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import React, {useMemo} from 'react';
import type {StyleProp, TextStyle, ViewStyle} from 'react-native';
import {View} from 'react-native';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
Expand Down Expand Up @@ -45,8 +46,25 @@ type ConnectionLayoutProps = {

/** Style of the subtitle text */
subTitleStyle?: StyleProp<TextStyle> | undefined;

/** Whether to use ScrollView or not */
shouldUseScrollView?: boolean;
};

type ConnectionLayoutContentProps = Pick<ConnectionLayoutProps, 'title' | 'titleStyle' | 'subtitle' | 'subTitleStyle' | 'children'>;

function ConnectionLayoutContent({title, titleStyle, subtitle, subTitleStyle, children}: ConnectionLayoutContentProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
return (
<>
{title && <Text style={[styles.pb5, titleStyle]}>{translate(title)}</Text>}
{subtitle && <Text style={[styles.textLabelSupporting, subTitleStyle]}>{translate(subtitle)}</Text>}
{children}
</>
);
}

function ConnectionLayout({
displayName,
headerTitle,
Expand All @@ -59,10 +77,24 @@ function ConnectionLayout({
contentContainerStyle,
titleStyle,
subTitleStyle,
shouldUseScrollView = true,
}: ConnectionLayoutProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();

const renderSelectionContent = useMemo(
() => (
<ConnectionLayoutContent
title={title}
subtitle={subtitle}
subTitleStyle={subTitleStyle}
titleStyle={titleStyle}
>
{children}
</ConnectionLayoutContent>
),
[title, subtitle, titleStyle, subTitleStyle, children],
);

return (
<AccessOrNotFoundWrapper
policyID={policyID}
Expand All @@ -78,11 +110,11 @@ function ConnectionLayout({
title={translate(headerTitle)}
onBackButtonPress={() => Navigation.goBack()}
/>
<ScrollView contentContainerStyle={contentContainerStyle}>
{title && <Text style={[styles.pb5, titleStyle]}>{translate(title)}</Text>}
{subtitle && <Text style={[styles.textLabelSupporting, subTitleStyle]}>{translate(subtitle)}</Text>}
{children}
</ScrollView>
{shouldUseScrollView ? (
<ScrollView contentContainerStyle={contentContainerStyle}>{renderSelectionContent}</ScrollView>
) : (
<View style={contentContainerStyle}>{renderSelectionContent}</View>
)}
</ScreenWrapper>
</AccessOrNotFoundWrapper>
);
Expand Down

0 comments on commit 23297de

Please sign in to comment.