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

feat: breakpoints #1870

Merged
merged 2 commits into from
May 27, 2024
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 src/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const Button = ({
return {
...textStyle,
...(text && icon && { marginLeft: 8 }),
...(text && !icon && { maxWidth: '100%', textAlign: 'center' }), // on android text sometimes get shrinked. So if there is no icon, make sure it takes the full width
...(variant === 'primary' ? {} : { color: white80 }),
...(disabled && !icon && { color: white32 }),
...Platform.select({
Expand Down
4 changes: 3 additions & 1 deletion src/components/HeadlinesWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ const HeadlinesWidget = ({
activeOpacity={0.9}
hitSlop={{ right: 15, bottom: 15, left: 15 }}
onPress={(): void => {
if (link) openAppURL(link);
if (link) {
openAppURL(link);
}
}}>
<View style={styles.columnLeft}>
<CaptionB color="white50" numberOfLines={1}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/SuggestionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ const styles = StyleSheet.create({
width: CARD_SIZE,
height: CARD_SIZE,
borderRadius: CARD_BORDER_RADIUS,
paddingHorizontal: 16,
paddingHorizontal: 15,
paddingBottom: 14,
},
pressable: {
Expand Down
8 changes: 6 additions & 2 deletions src/screens/Settings/ElectrumConfig/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import { refreshWallet, rescanAddresses } from '../../../utils/wallet';
import { EAvailableNetwork } from '../../../utils/networks';
import { updateActivityList } from '../../../store/utils/activity';
import useBreakpoints from '../../../styles/breakpoints';

type RadioButtonItem = { label: string; value: EProtocol };

Expand Down Expand Up @@ -87,6 +88,7 @@
navigation,
}: SettingsScreenProps<'ElectrumConfig'>): ReactElement => {
const { t } = useTranslation('settings');
const br = useBreakpoints();
const dispatch = useAppDispatch();
const selectedNetwork = useAppSelector(selectedNetworkSelector);
const customElectrumPeers = useAppSelector((state) => {
Expand Down Expand Up @@ -337,7 +339,7 @@
/>
</View>

<View style={styles.buttons}>
<View style={[styles.buttons, br.up('smphone') && styles.buttonsRow]}>

Check failure on line 342 in src/screens/Settings/ElectrumConfig/index.tsx

View workflow job for this annotation

GitHub Actions / Run type check

Argument of type '"smphone"' is not assignable to parameter of type '"sm"'.
<Button
style={styles.button}
text={t('es.button_reset')}
Expand Down Expand Up @@ -388,10 +390,12 @@
marginTop: 11,
},
buttons: {
flexDirection: 'row',
marginTop: 'auto',
gap: 16,
},
buttonsRow: {
flexDirection: 'row',
},
button: {
flex: 1,
},
Expand Down
10 changes: 7 additions & 3 deletions src/screens/Settings/Lightning/Channels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import { EUnit } from '../../../store/types/wallet';
import { showBottomSheet } from '../../../store/utils/ui';
import { EChannelStatus, TChannel } from '../../../store/types/lightning';
import useBreakpoints from '../../../styles/breakpoints';

/**
* Convert pending (non-channel) blocktank orders to (fake) channels.
Expand Down Expand Up @@ -227,6 +228,7 @@
const [spendingStuckOutputs, setSpendingStuckOutputs] = useState(false);

const colors = useColors();
const br = useBreakpoints();
const { localBalance, remoteBalance } = useLightningBalance();
const selectedWallet = useAppSelector(selectedWalletSelector);
const selectedNetwork = useAppSelector(selectedNetworkSelector);
Expand Down Expand Up @@ -648,7 +650,7 @@
</View>
)}

<View style={styles.buttons}>
<View style={[styles.buttons, br.up('smphone') && styles.buttonsRow]}>

Check failure on line 653 in src/screens/Settings/Lightning/Channels.tsx

View workflow job for this annotation

GitHub Actions / Run type check

Argument of type '"smphone"' is not assignable to parameter of type '"sm"'.
<Button
style={styles.button}
text={t('conn_button_export_logs')}
Expand Down Expand Up @@ -724,16 +726,18 @@
},
devButtons: {
marginTop: 'auto',
marginBottom: 16,
},
devButton: {
marginTop: 8,
},
buttons: {
flexDirection: 'row',
alignItems: 'center',
marginTop: 'auto',
gap: 16,
},
buttonsRow: {
flexDirection: 'row',
},
button: {
flex: 1,
},
Expand Down
9 changes: 6 additions & 3 deletions src/screens/Settings/RGSServer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
selectedWalletSelector,
} from '../../../store/reselect/wallet';
import { rapidGossipSyncUrlSelector } from '../../../store/reselect/settings';

import { initialSettingsState } from '../../../store/shapes/settings';
import NavigationHeader from '../../../components/NavigationHeader';
import SafeAreaInset from '../../../components/SafeAreaInset';
import Button from '../../../components/Button';
import type { SettingsScreenProps } from '../../../navigation/types';
import { setupLdk } from '../../../utils/lightning';
import { showToast } from '../../../utils/notifications';
import useBreakpoints from '../../../styles/breakpoints';

const isValidURL = (data: string): boolean => {
const pattern = new RegExp(
Expand All @@ -48,6 +48,7 @@
navigation,
}: SettingsScreenProps<'RGSServer'>): ReactElement => {
const { t } = useTranslation('settings');
const br = useBreakpoints();
const dispatch = useAppDispatch();
const selectedNetwork = useAppSelector(selectedNetworkSelector);
const selectedWallet = useAppSelector(selectedWalletSelector);
Expand Down Expand Up @@ -132,7 +133,7 @@
testID="RGSUrl"
/>

<View style={styles.buttons}>
<View style={[styles.buttons, br.up('smphone') && styles.buttonsRow]}>

Check failure on line 136 in src/screens/Settings/RGSServer/index.tsx

View workflow job for this annotation

GitHub Actions / Run type check

Argument of type '"smphone"' is not assignable to parameter of type '"sm"'.
<Button
style={styles.button}
text={t('es.button_reset')}
Expand Down Expand Up @@ -179,10 +180,12 @@
marginTop: 5,
},
buttons: {
flexDirection: 'row',
marginTop: 'auto',
gap: 16,
},
buttonsRow: {
flexDirection: 'row',
},
button: {
flex: 1,
},
Expand Down
39 changes: 39 additions & 0 deletions src/styles/breakpoints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import memoize from 'lodash/memoize';
import { Dimensions } from 'react-native';

const { width } = Dimensions.get('window');

enum BREAKPOINTS {
// xs = 320,
sm = 360, // small android phone: 360
// md = 375, // iphoneSE and up
// lg = 390, // iphone15 and up
// xl = 400,
}

/**
* Check if the screen is at least the specified breakpoint
**/
const up = (min: keyof typeof BREAKPOINTS): boolean => {
return width > BREAKPOINTS[min];
};

/**
* Check if the screen is at most the specified breakpoint
**/
const down = (max: keyof typeof BREAKPOINTS): boolean => {
return width <= BREAKPOINTS[max];
};

const breakpoints = {
up: memoize(up),
down: memoize(down),
};

type TBreakpoints = typeof breakpoints;

const useBreakpoints = (): TBreakpoints => {
return breakpoints;
};

export default useBreakpoints;
Loading