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

Add ability to use View in ConnectionLayout #41664

Merged
merged 1 commit into from
May 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading