Skip to content

Commit

Permalink
refactor: add prop elevated, remove old screenshots, add prop annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewalczak committed Mar 27, 2022
1 parent 8cbbd4d commit 36d06f4
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 126 deletions.
152 changes: 86 additions & 66 deletions example/src/Examples/AppbarExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Text,
useTheme,
RadioButton,
List,
} from 'react-native-paper';
import ScreenWrapper from '../ScreenWrapper';
import { yellowA200 } from '../../../src/styles/themes/v2/colors';
Expand All @@ -30,6 +31,7 @@ const AppbarExample = ({ navigation }: Props) => {
const [showExactTheme, setShowExactTheme] = React.useState(false);
const [appbarMode, setAppbarMode] = React.useState<AppbarModes>('small');
const [showCalendarIcon, setShowCalendarIcon] = React.useState(false);
const [showElevated, setShowElevated] = React.useState(false);

const { isV3 } = useTheme();

Expand All @@ -39,11 +41,12 @@ const AppbarExample = ({ navigation }: Props) => {
navigation.setOptions({
header: () => (
<Appbar.Header
style={showCustomColor ? styles.customColor : null}
style={[showCustomColor ? styles.customColor : null]}
theme={{
mode: showExactTheme ? 'exact' : 'adaptive',
}}
mode={appbarMode}
elevated={showElevated}
>
{showLeftIcon && (
<Appbar.BackAction onPress={() => navigation.goBack()} />
Expand Down Expand Up @@ -77,81 +80,101 @@ const AppbarExample = ({ navigation }: Props) => {
appbarMode,
showCalendarIcon,
isCenterAlignedMode,
showElevated,
]);

const TextComponent = isV3 ? Text : Paragraph;

return (
const renderDefaultOptions = () => (
<>
<ScreenWrapper
style={styles.container}
contentContainerStyle={styles.contentContainer}
>
<View style={styles.row}>
<TextComponent variant="labelLarge">Left icon</TextComponent>
<Switch value={showLeftIcon} onValueChange={setShowLeftIcon} />
</View>
{!isV3 && (
<View style={styles.row}>
<TextComponent variant="labelLarge">Left icon</TextComponent>
<Switch value={showLeftIcon} onValueChange={setShowLeftIcon} />
<TextComponent variant="labelLarge">Subtitle</TextComponent>
<Switch value={showSubtitle} onValueChange={setShowSubtitle} />
</View>
{!isV3 && (
<View style={styles.row}>
<TextComponent variant="labelLarge">Subtitle</TextComponent>
<Switch value={showSubtitle} onValueChange={setShowSubtitle} />
</View>
)}
)}
<View style={styles.row}>
<TextComponent variant="labelLarge">Search icon</TextComponent>
<Switch value={showSearchIcon} onValueChange={setShowSearchIcon} />
</View>
<View style={styles.row}>
<TextComponent variant="labelLarge">More icon</TextComponent>
<Switch value={showMoreIcon} onValueChange={setShowMoreIcon} />
</View>
{isV3 && (
<View style={styles.row}>
<TextComponent variant="labelLarge">Search icon</TextComponent>
<Switch value={showSearchIcon} onValueChange={setShowSearchIcon} />
<TextComponent variant="labelLarge">Calendar icon</TextComponent>
<Switch
value={isCenterAlignedMode ? false : showCalendarIcon}
disabled={isCenterAlignedMode}
onValueChange={setShowCalendarIcon}
/>
</View>
)}
<View style={styles.row}>
<TextComponent variant="labelLarge">Custom Color</TextComponent>
<Switch value={showCustomColor} onValueChange={setShowCustomColor} />
</View>
<View style={styles.row}>
<TextComponent variant="labelLarge">Exact Dark Theme</TextComponent>
<Switch value={showExactTheme} onValueChange={setShowExactTheme} />
</View>
{isV3 && (
<View style={styles.row}>
<TextComponent variant="labelLarge">More icon</TextComponent>
<Switch value={showMoreIcon} onValueChange={setShowMoreIcon} />
<TextComponent variant="labelLarge">Elevated</TextComponent>
<Switch value={showElevated} onValueChange={setShowElevated} />
</View>
{isV3 && (
<View style={styles.row}>
<TextComponent variant="labelLarge">Calendar icon</TextComponent>
<Switch
value={isCenterAlignedMode ? false : showCalendarIcon}
disabled={isCenterAlignedMode}
onValueChange={setShowCalendarIcon}
/>
</View>
)}
</>
);

return (
<>
<ScreenWrapper
style={styles.container}
contentContainerStyle={styles.contentContainer}
>
{isV3 ? (
<List.Section title="Default options">
{renderDefaultOptions()}
</List.Section>
) : (
renderDefaultOptions()
)}
<View style={styles.row}>
<TextComponent variant="labelLarge">Custom Color</TextComponent>
<Switch value={showCustomColor} onValueChange={setShowCustomColor} />
</View>
<View style={styles.row}>
<TextComponent variant="labelLarge">Exact Dark Theme</TextComponent>
<Switch value={showExactTheme} onValueChange={setShowExactTheme} />
</View>
{isV3 && (
<RadioButton.Group
value={appbarMode}
onValueChange={(value: string) =>
setAppbarMode(value as AppbarModes)
}
>
<TextComponent variant="labelLarge" style={styles.appbarMode}>
Appbar Mode
</TextComponent>
<View style={styles.row}>
<TextComponent variant="labelLarge">
Small (default)
</TextComponent>
<RadioButton value="small" />
</View>
<View style={styles.row}>
<TextComponent variant="labelLarge">Medium</TextComponent>
<RadioButton value="medium" />
</View>
<View style={styles.row}>
<TextComponent variant="labelLarge">Large</TextComponent>
<RadioButton value="large" />
</View>
<View style={styles.row}>
<TextComponent variant="labelLarge">Center-aligned</TextComponent>
<RadioButton value="center-aligned" />
</View>
</RadioButton.Group>
<List.Section title="Appbar Modes">
<RadioButton.Group
value={appbarMode}
onValueChange={(value: string) =>
setAppbarMode(value as AppbarModes)
}
>
<View style={styles.row}>
<TextComponent variant="labelLarge">
Small (default)
</TextComponent>
<RadioButton value="small" />
</View>
<View style={styles.row}>
<TextComponent variant="labelLarge">Medium</TextComponent>
<RadioButton value="medium" />
</View>
<View style={styles.row}>
<TextComponent variant="labelLarge">Large</TextComponent>
<RadioButton value="large" />
</View>
<View style={styles.row}>
<TextComponent variant="labelLarge">
Center-aligned
</TextComponent>
<RadioButton value="center-aligned" />
</View>
</RadioButton.Group>
</List.Section>
)}
</ScreenWrapper>
<Appbar
Expand Down Expand Up @@ -200,7 +223,4 @@ const styles = StyleSheet.create({
customColor: {
backgroundColor: yellowA200,
},
appbarMode: {
textAlign: 'center',
},
});
3 changes: 2 additions & 1 deletion example/src/RootNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ export default function Root() {
headerMode="screen"
screenOptions={{
header: ({ navigation, scene, previous }) => (
<Appbar.Header>
<Appbar.Header elevated>
{previous ? (
<Appbar.BackAction onPress={() => navigation.goBack()} />
) : (navigation as any).openDrawer ? (
<Appbar.Action
icon="menu"
isLeading
onPress={() =>
(navigation as any as DrawerNavigationProp<{}>).openDrawer()
}
Expand Down
15 changes: 1 addition & 14 deletions src/components/Appbar/AppbarAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Props = React.ComponentPropsWithoutRef<typeof IconButton> & {
*/
onPress?: () => void;
/**
* `Available in v3.x`
* @supported Available in v3.x with theme version 3
*
* Whether it's the leading button.
*/
Expand All @@ -47,19 +47,6 @@ type Props = React.ComponentPropsWithoutRef<typeof IconButton> & {

/**
* A component used to display an action item in the appbar.
* <div class="screenshots">
* <figure>
* <img class="medium" src="screenshots/appbar-action-android.png" />
* <figcaption>Android</figcaption>
* </figure>
* </div>
*
* <div class="screenshots">
* <figure>
* <img class="medium" src="screenshots/appbar-action-ios.png" />
* <figcaption>iOS</figcaption>
* </figure>
* </div>
*
* ## Usage
* ```js
Expand Down
14 changes: 0 additions & 14 deletions src/components/Appbar/AppbarBackAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,6 @@ type Props = $Omit<
/**
* A component used to display a back button in the appbar.
*
* <div class="screenshots">
* <figure>
* <img class="medium" src="screenshots/appbar-backaction-android.png" />
* <figcaption>Android</figcaption>
* </figure>
* </div>
*
* <div class="screenshots">
* <figure>
* <img class="medium" src="screenshots/appbar-backaction-ios.png" />
* <figcaption>iOS</figcaption>
* </figure>
* </div>
*
* ## Usage
* ```js
* import * as React from 'react';
Expand Down
17 changes: 6 additions & 11 deletions src/components/Appbar/AppbarContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { withTheme } from '../../core/theming';
import { white } from '../../styles/themes/v2/colors';

import type { $RemoveChildren, Theme } from '../../types';
import { AppbarModes, modeTextVariant } from './utils';
import { modeTextVariant } from './utils';

type Props = $RemoveChildren<typeof View> & {
/**
Expand All @@ -36,12 +36,12 @@ type Props = $RemoveChildren<typeof View> & {
*/
titleRef?: React.RefObject<Text>;
/**
* @deprecated
* @deprecated Deprecated in v3.x
* Text for the subtitle.
*/
subtitle?: React.ReactNode;
/**
* @deprecated
* @deprecated Deprecated in v3.x
* Style for the subtitle.
*/
subtitleStyle?: StyleProp<TextStyle>;
Expand All @@ -50,15 +50,15 @@ type Props = $RemoveChildren<typeof View> & {
*/
onPress?: () => void;
/**
* `Available in v3.x`
* @supported Available in v3.x with theme version 3
*
* Mode of the Appbar.
* - `small` - Appbar with default height (56).
* - `medium` - Appbar with medium height (112).
* - `large` - Appbar with large height (152).
* - `center-aligned` - Appbar with default height and center-aligned title.
*/
mode?: AppbarModes;
mode?: 'small' | 'medium' | 'large' | 'center-aligned';
style?: StyleProp<ViewStyle>;
/**
* @optional
Expand All @@ -69,12 +69,6 @@ type Props = $RemoveChildren<typeof View> & {
/**
* A component used to display a title and optional subtitle in an appbar.
*
* <div class="screenshots">
* <figure>
* <img class="medium" src="screenshots/appbar-content.png" />
* </figure>
* </div>
*
* ## Usage
* ```js
* import * as React from 'react';
Expand Down Expand Up @@ -122,6 +116,7 @@ const AppbarContent = ({
return (
<TouchableWithoutFeedback onPress={onPress} disabled={!onPress}>
<View
pointerEvents="box-none"
style={[styles.container, isV3 && modeContainerStyles[mode], style]}
{...rest}
>
Expand Down
Loading

0 comments on commit 36d06f4

Please sign in to comment.