You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-07-16 00:14:34 +02:00
Mobile: Improve dialog styling on large and notched screens (#10470)
This commit is contained in:
@ -40,6 +40,7 @@ const useStyles = (themeId: number, containerStyle: ViewStyle) => {
|
|||||||
|
|
||||||
height: windowSize.height * 0.9,
|
height: windowSize.height * 0.9,
|
||||||
width: windowSize.width * 0.97,
|
width: windowSize.width * 0.97,
|
||||||
|
flexShrink: 1,
|
||||||
|
|
||||||
// Center
|
// Center
|
||||||
marginLeft: 'auto',
|
marginLeft: 'auto',
|
||||||
@ -47,6 +48,13 @@ const useStyles = (themeId: number, containerStyle: ViewStyle) => {
|
|||||||
|
|
||||||
...containerStyle,
|
...containerStyle,
|
||||||
},
|
},
|
||||||
|
dialogContainer: {
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'row',
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
flexGrow: 1,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}, [themeId, windowSize.width, windowSize.height, containerStyle]);
|
}, [themeId, windowSize.width, windowSize.height, containerStyle]);
|
||||||
};
|
};
|
||||||
@ -69,7 +77,9 @@ const DismissibleDialog: React.FC<Props> = props => {
|
|||||||
visible={props.visible}
|
visible={props.visible}
|
||||||
onDismiss={props.onDismiss}
|
onDismiss={props.onDismiss}
|
||||||
onRequestClose={props.onDismiss}
|
onRequestClose={props.onDismiss}
|
||||||
|
containerStyle={styles.dialogContainer}
|
||||||
animationType='fade'
|
animationType='fade'
|
||||||
|
backgroundColor='rgba(0, 0, 0, 0.1)'
|
||||||
transparent={true}
|
transparent={true}
|
||||||
>
|
>
|
||||||
<Surface style={styles.dialog} elevation={1}>
|
<Surface style={styles.dialog} elevation={1}>
|
||||||
|
@ -1,36 +1,58 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { Modal, ModalProps, StyleSheet, View, ViewStyle } from 'react-native';
|
import { useMemo } from 'react';
|
||||||
|
import { Modal, ModalProps, StyleSheet, View, ViewStyle, useWindowDimensions } from 'react-native';
|
||||||
import { hasNotch } from 'react-native-device-info';
|
import { hasNotch } from 'react-native-device-info';
|
||||||
|
|
||||||
interface ModalElementProps extends ModalProps {
|
interface ModalElementProps extends ModalProps {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
containerStyle?: ViewStyle;
|
containerStyle?: ViewStyle;
|
||||||
elevation?: number;
|
backgroundColor?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const useStyles = (backgroundColor?: string) => {
|
||||||
|
const { width: windowWidth, height: windowHeight } = useWindowDimensions();
|
||||||
|
const isLandscape = windowWidth > windowHeight;
|
||||||
|
return useMemo(() => {
|
||||||
|
return StyleSheet.create({
|
||||||
|
contentWrapper: isLandscape ? {
|
||||||
|
marginRight: hasNotch() ? 60 : 0,
|
||||||
|
marginLeft: hasNotch() ? 60 : 0,
|
||||||
|
marginTop: 15,
|
||||||
|
marginBottom: 15,
|
||||||
|
} : {
|
||||||
|
marginTop: hasNotch() ? 65 : 15,
|
||||||
|
marginBottom: hasNotch() ? 35 : 15,
|
||||||
|
},
|
||||||
|
modalBackground: { backgroundColor, flexGrow: 1 },
|
||||||
|
});
|
||||||
|
}, [isLandscape, backgroundColor]);
|
||||||
|
};
|
||||||
|
|
||||||
const ModalElement: React.FC<ModalElementProps> = ({
|
const ModalElement: React.FC<ModalElementProps> = ({
|
||||||
children,
|
children,
|
||||||
containerStyle,
|
containerStyle,
|
||||||
|
backgroundColor,
|
||||||
...modalProps
|
...modalProps
|
||||||
}) => {
|
}) => {
|
||||||
|
const styles = useStyles(backgroundColor);
|
||||||
|
|
||||||
|
// contentWrapper adds padding. To allow styling the region outside of the modal
|
||||||
|
// (e.g. to add a background), the content is wrapped twice.
|
||||||
|
const content = (
|
||||||
|
<View style={[styles.contentWrapper, containerStyle]}>
|
||||||
|
{children}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
|
||||||
// supportedOrientations: On iOS, this allows the dialog to be shown in non-portrait orientations.
|
// supportedOrientations: On iOS, this allows the dialog to be shown in non-portrait orientations.
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
supportedOrientations={['portrait', 'portrait-upside-down', 'landscape', 'landscape-left', 'landscape-right']}
|
supportedOrientations={['portrait', 'portrait-upside-down', 'landscape', 'landscape-left', 'landscape-right']}
|
||||||
{...modalProps}
|
{...modalProps}
|
||||||
>
|
>
|
||||||
<View style={[styleSheet.modalContainer, containerStyle ? containerStyle : null]}>
|
<View style={styles.modalBackground}>{content}</View>
|
||||||
{children}
|
|
||||||
</View>
|
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const styleSheet = StyleSheet.create({
|
|
||||||
modalContainer: {
|
|
||||||
marginTop: hasNotch() ? 65 : 15,
|
|
||||||
marginBottom: hasNotch() ? 35 : 15,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default ModalElement;
|
export default ModalElement;
|
||||||
|
Reference in New Issue
Block a user