Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ const config = {
ListItem: 'List/ListItem',
ListSection: 'List/ListSection',
ListSubheader: 'List/ListSubheader',
ListImage: 'List/ListImage',
},
Menu: {
Menu: 'Menu/Menu',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ const AnimatedFABExample = () => {

const isIOS = Platform.OS === 'ios';

const [extended, setExtended] = React.useState<boolean>(true);
const [visible, setVisible] = React.useState<boolean>(true);

const [extended, setExtended] = React.useState(true);
const [visible, setVisible] = React.useState(true);
const [controls, setControls] = React.useState<Controls>(initialControls);

const { current: velocity } = React.useRef<Animated.Value>(
Expand Down
4 changes: 2 additions & 2 deletions example/src/Examples/BannerExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ const PHOTOS = Array.from({ length: 24 }).map(
);

const BannerExample = () => {
const [visible, setVisible] = React.useState<boolean>(true);
const [useCustomTheme, setUseCustomTheme] = React.useState<boolean>(false);
const theme = useTheme();

const [visible, setVisible] = React.useState<boolean>(true);
const [useCustomTheme, setUseCustomTheme] = React.useState<boolean>(false);
const [height, setHeight] = React.useState(0);

const handleLayout = ({ nativeEvent }: LayoutChangeEvent) => {
Expand Down
3 changes: 2 additions & 1 deletion example/src/Examples/ChipExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import { Chip, List, MD3Colors, Snackbar, Text } from 'react-native-paper';

import ScreenWrapper from '../ScreenWrapper';

const customColor = MD3Colors.error50;

const ChipExample = () => {
const [snackbarProperties, setSnackbarProperties] = React.useState({
visible: false,
text: '',
});
const customColor = MD3Colors.error50;

return (
<>
Expand Down
4 changes: 2 additions & 2 deletions example/src/Examples/ListSectionExample.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { StyleSheet, Image, View } from 'react-native';

import { Caption, List, Text, Chip, Divider } from 'react-native-paper';
import { List, Text, Chip, Divider } from 'react-native-paper';

import ScreenWrapper from '../ScreenWrapper';
const ListSectionExample = () => {
Expand Down Expand Up @@ -97,7 +97,7 @@ const ListSectionExample = () => {
>
List Item
</Text>
<Caption>Yesterday</Caption>
<Text>Yesterday</Text>
</View>
)}
description={({
Expand Down
5 changes: 3 additions & 2 deletions example/src/Examples/ProgressBarExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ class ClassProgressBar extends React.Component {
const AnimatedProgressBar = Animated.createAnimatedComponent(ClassProgressBar);

const ProgressBarExample = () => {
const [visible, setVisible] = React.useState<boolean>(true);
const [progress, setProgress] = React.useState<number>(0.3);
const theme = useTheme();

const [visible, setVisible] = React.useState(true);
const [progress, setProgress] = React.useState(0.3);
const { current: progressBarValue } = React.useRef(new Animated.Value(0));

const runCustomAnimation = () => {
Expand Down
12 changes: 6 additions & 6 deletions src/components/ActivityIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ const ActivityIndicator = ({
theme: themeOverrides,
...rest
}: Props) => {
const theme = useInternalTheme(themeOverrides);
const {
animation: { scale },
colors: { primary },
} = useInternalTheme(themeOverrides);

const { current: timer } = React.useRef<Animated.Value>(
new Animated.Value(0)
);
Expand All @@ -75,10 +79,6 @@ const ActivityIndicator = ({
undefined
);

const {
animation: { scale },
} = theme;

const startRotation = React.useCallback(() => {
// Show indicator
Animated.timing(fade, {
Expand Down Expand Up @@ -130,7 +130,7 @@ const ActivityIndicator = ({
}
}, [animating, fade, hidesWhenStopped, startRotation, scale, timer]);

const color = indicatorColor || theme.colors?.primary;
const color = indicatorColor || primary;
const size =
typeof indicatorSize === 'string'
? indicatorSize === 'small'
Expand Down
45 changes: 10 additions & 35 deletions src/components/Appbar/Appbar.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import * as React from 'react';
import {
Animated,
Platform,
StyleProp,
StyleSheet,
View,
ViewStyle,
ColorValue,
} from 'react-native';

import color from 'color';

import AppbarContent from './AppbarContent';
import {
AppbarModes,
DEFAULT_APPBAR_HEIGHT,
getAppbarBackgroundColor,
modeAppbarHeight,
renderAppbarContent,
Expand Down Expand Up @@ -165,11 +161,10 @@ const Appbar = ({
...rest
}: Props) => {
const theme = useInternalTheme(themeOverrides);
const { isV3 } = theme;
const flattenedStyle = StyleSheet.flatten(style);
const {
backgroundColor: customBackground,
elevation = isV3 ? (elevated ? 2 : 0) : 4,
elevation = elevated ? 2 : 0,
...restStyle
} = (flattenedStyle || {}) as Exclude<typeof flattenedStyle, number> & {
elevation?: number;
Expand All @@ -178,34 +173,26 @@ const Appbar = ({

const backgroundColor = getAppbarBackgroundColor(
theme,
elevation,
customBackground,
elevated
);

const isMode = (modeToCompare: AppbarModes) => {
return isV3 && mode === modeToCompare;
return mode === modeToCompare;
};

let isDark = false;

if (typeof dark === 'boolean') {
isDark = dark;
} else if (!isV3) {
isDark =
backgroundColor === 'transparent'
? false
: typeof backgroundColor === 'string'
? !color(backgroundColor).isLight()
: true;
}

const isV3CenterAlignedMode = isV3 && isMode('center-aligned');
const isCenterAlignedMode = isMode('center-aligned');

let shouldCenterContent = false;
let shouldAddLeftSpacing = false;
let shouldAddRightSpacing = false;
if ((!isV3 && Platform.OS === 'ios') || isV3CenterAlignedMode) {
if (isCenterAlignedMode) {
let hasAppbarContent = false;
let leftItemsCount = 0;
let rightItemsCount = 0;
Expand All @@ -225,14 +212,12 @@ const Appbar = ({
});

shouldCenterContent =
hasAppbarContent &&
leftItemsCount < 2 &&
rightItemsCount < (isV3 ? 3 : 2);
hasAppbarContent && leftItemsCount < 2 && rightItemsCount < 3;
shouldAddLeftSpacing = shouldCenterContent && leftItemsCount === 0;
shouldAddRightSpacing = shouldCenterContent && rightItemsCount === 0;
}

const spacingStyle = isV3 ? styles.v3Spacing : styles.spacing;
const spacingStyle = styles.v3Spacing;

const insets = {
paddingBottom: safeAreaInsets?.bottom,
Expand All @@ -247,26 +232,24 @@ const Appbar = ({
{ backgroundColor },
styles.appbar,
{
height: isV3 ? modeAppbarHeight[mode] : DEFAULT_APPBAR_HEIGHT,
height: modeAppbarHeight[mode],
},
insets,
restStyle,
!theme.isV3 && { elevation },
]}
elevation={elevation as MD3Elevation}
{...rest}
>
{shouldAddLeftSpacing ? <View style={spacingStyle} /> : null}
{(!isV3 || isMode('small') || isMode('center-aligned')) && (
{(isMode('small') || isMode('center-aligned')) && (
<>
{/* Render only the back action at first place */}
{renderAppbarContent({
children,
isDark,
theme,
isV3,
renderOnly: ['Appbar.BackAction'],
shouldCenterContent: isV3CenterAlignedMode || shouldCenterContent,
shouldCenterContent: isCenterAlignedMode || shouldCenterContent,
})}
{/* Render the rest of the content except the back action */}
{renderAppbarContent({
Expand All @@ -277,9 +260,8 @@ const Appbar = ({
],
isDark,
theme,
isV3,
renderExcept: ['Appbar.BackAction'],
shouldCenterContent: isV3CenterAlignedMode || shouldCenterContent,
shouldCenterContent: isCenterAlignedMode || shouldCenterContent,
})}
</>
)}
Expand All @@ -296,14 +278,12 @@ const Appbar = ({
{renderAppbarContent({
children,
isDark,
isV3,
renderOnly: ['Appbar.BackAction'],
mode,
})}
{renderAppbarContent({
children: filterAppbarActions(children, true),
isDark,
isV3,
renderOnly: ['Appbar.Action'],
mode,
})}
Expand All @@ -312,7 +292,6 @@ const Appbar = ({
{renderAppbarContent({
children: filterAppbarActions(children),
isDark,
isV3,
renderExcept: [
'Appbar',
'Appbar.BackAction',
Expand All @@ -326,7 +305,6 @@ const Appbar = ({
{renderAppbarContent({
children,
isDark,
isV3,
renderOnly: ['Appbar.Content'],
mode,
})}
Expand All @@ -343,9 +321,6 @@ const styles = StyleSheet.create({
alignItems: 'center',
paddingHorizontal: 4,
},
spacing: {
width: 48,
},
v3Spacing: {
width: 52,
},
Expand Down
14 changes: 6 additions & 8 deletions src/components/Appbar/AppbarAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import type {
ViewStyle,
} from 'react-native';

import color from 'color';
import type { ThemeProp } from 'src/types';

import { useInternalTheme } from '../../core/theming';
import { black } from '../../styles/themes/v2/colors';
import { forwardRef } from '../../utils/forwardRef';
import type { IconSource } from '../Icon';
import IconButton from '../IconButton/IconButton';
Expand Down Expand Up @@ -97,15 +95,15 @@ const AppbarAction = forwardRef<View, Props>(
}: Props,
ref
) => {
const theme = useInternalTheme(themeOverrides);
const {
colors: { onSurface, onSurfaceVariant },
} = useInternalTheme(themeOverrides);

const actionIconColor = iconColor
? iconColor
: theme.isV3
? isLeading
? theme.colors.onSurface
: theme.colors.onSurfaceVariant
: color(black).alpha(0.54).rgb().string();
: isLeading
? onSurface
: onSurfaceVariant;

return (
<IconButton
Expand Down
Loading
Loading