Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d95b628

Browse files
committed
Implement CardUi4
Largely copied from Card. - Styled according to UI4 guidelines - Adds new functionality to automatically add styled dividers when multiple children are given.
1 parent c6efd03 commit d95b628

File tree

7 files changed

+172
-2
lines changed

7 files changed

+172
-2
lines changed

‎src/__tests__/scenes/__snapshots__/FioAddressListScene.test.tsx.snap‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ exports[`FioAddressList should render with loading props 1`] = `
6969
"cameraOverlayColor": "#000000",
7070
"cameraOverlayOpEnd": 0.3,
7171
"cameraOverlayOpStart": 0.7,
72+
"cardBackgroundUi4": "rgb(22, 50, 58)",
7273
"cardBorder": 1,
7374
"cardBorderColor": "rgba(255, 255, 255, .1)",
7475
"cardBorderRadius": 4,
76+
"cardRadiusRemUi4": 1,
7577
"clipboardPopupText": "#000000",
7678
"confirmationSlider": "#2B333A",
7779
"confirmationSliderArrow": "#1b2f3b",
@@ -525,9 +527,11 @@ exports[`FioAddressList should render with loading props 1`] = `
525527
"cameraOverlayColor": "#000000",
526528
"cameraOverlayOpEnd": 0.3,
527529
"cameraOverlayOpStart": 0.7,
530+
"cardBackgroundUi4": "rgb(22, 50, 58)",
528531
"cardBorder": 1,
529532
"cardBorderColor": "rgba(255, 255, 255, .1)",
530533
"cardBorderRadius": 4,
534+
"cardRadiusRemUi4": 1,
531535
"clipboardPopupText": "#000000",
532536
"confirmationSlider": "#2B333A",
533537
"confirmationSliderArrow": "#1b2f3b",

‎src/components/ui4/CardUi4.tsx‎

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import * as React from 'react'
2+
import { TouchableHighlight, View } from 'react-native'
3+
4+
import { useHandler } from '../../hooks/useHandler'
5+
import { triggerHaptic } from '../../util/haptic'
6+
import { showError } from '../services/AirshipInstance'
7+
import { cacheStyles, Theme, useTheme } from '../services/ThemeContext'
8+
import { SectionView } from './SectionView'
9+
10+
export type CardType = 'default' | 'warning' | 'error'
11+
12+
interface Props {
13+
children: React.ReactNode | React.ReactNode[]
14+
icon?: React.ReactNode
15+
onLongPress?: () => Promise<void> | void
16+
onPress?: () => Promise<void> | void
17+
// cardType?: CardType // TODO
18+
}
19+
20+
/**
21+
* Rounded card that automatically adds horizontal dividers between each child,
22+
* aligned in a column layout. Adds no dividers if only one child is given.
23+
*/
24+
export const CardUi4 = (props: Props) => {
25+
const { children, icon, onLongPress, onPress } = props
26+
const theme = useTheme()
27+
const styles = getStyles(theme)
28+
29+
const handlePress = useHandler(async () => {
30+
if (onPress != null) {
31+
triggerHaptic('impactLight')
32+
try {
33+
await onPress()
34+
} catch (err) {
35+
showError(err)
36+
}
37+
}
38+
})
39+
40+
const handleLongPress = useHandler(async () => {
41+
if (onLongPress != null) {
42+
triggerHaptic('impactLight')
43+
try {
44+
await onLongPress()
45+
} catch (err) {
46+
showError(err)
47+
}
48+
}
49+
})
50+
51+
return (
52+
<TouchableHighlight
53+
accessible={false}
54+
onPress={handlePress}
55+
onLongPress={handleLongPress}
56+
disabled={handlePress == null && handleLongPress == null}
57+
underlayColor={theme.touchHighlightUi4}
58+
style={styles.cardContainer}
59+
>
60+
<>
61+
{icon == null ? null : <View style={styles.iconContainer}>{icon}</View>}
62+
<SectionView>{children}</SectionView>
63+
</>
64+
</TouchableHighlight>
65+
)
66+
}
67+
68+
// TODO: Adjust margin/padding so everything combines with correct layout no
69+
// matter the combination of UI4 components.
70+
const getStyles = cacheStyles((theme: Theme) => ({
71+
cardContainer: {
72+
backgroundColor: theme.cardBackgroundUi4,
73+
borderRadius: theme.rem(theme.cardRadiusRemUi4),
74+
margin: theme.rem(0.5),
75+
padding: theme.rem(0.5),
76+
flexDirection: 'row'
77+
},
78+
iconContainer: {
79+
margin: theme.rem(0.25),
80+
justifyContent: 'center',
81+
alignContent: 'center'
82+
},
83+
warning: {
84+
borderColor: theme.warningIcon
85+
}
86+
}))

‎src/components/ui4/SectionView.tsx‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import * as React from 'react'
2+
import { View } from 'react-native'
3+
4+
import { cacheStyles, Theme, useTheme } from '../services/ThemeContext'
5+
6+
interface Props {
7+
children: React.ReactNode | React.ReactNode[]
8+
}
9+
10+
/**
11+
* View that automatically adds horizontal dividers between each child, aligned
12+
* in a column layout. Adds no dividers if only one child is given.
13+
*/
14+
export const SectionView = (props: Props): JSX.Element | null => {
15+
const { children } = props
16+
const theme = useTheme()
17+
const styles = getStyles(theme)
18+
19+
const nonNullChildren = React.Children.map(children, child => {
20+
if (child != null) {
21+
return child
22+
}
23+
})
24+
const numChildren = React.Children.count(nonNullChildren)
25+
26+
if (children == null || numChildren === 0) return null
27+
28+
// Add a line divider between each child if there's more than one:
29+
return (
30+
<View style={styles.container}>
31+
{numChildren === 1
32+
? nonNullChildren
33+
: React.Children.map(nonNullChildren, (child, index) => {
34+
if (index < numChildren - 1) {
35+
return (
36+
<>
37+
{child}
38+
<View style={styles.divider} />
39+
</>
40+
)
41+
}
42+
return child
43+
})}
44+
</View>
45+
)
46+
}
47+
48+
const getStyles = cacheStyles((theme: Theme) => ({
49+
container: {
50+
flexDirection: 'column',
51+
flex: 1
52+
},
53+
divider: {
54+
height: theme.thinLineWidth,
55+
marginHorizontal: theme.rem(0.5),
56+
borderBottomWidth: theme.thinLineWidth,
57+
borderBottomColor: theme.lineDivider
58+
}
59+
}))

‎src/theme/variables/edgeDark.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ const palette = {
6666
QuicksandRegular: 'Quicksand-Regular',
6767
QuicksandMedium: 'Quicksand-Medium',
6868
QuicksandSemiBold: 'Quicksand-SemiBold',
69-
QuicksandBold: 'Quicksand-Bold'
69+
QuicksandBold: 'Quicksand-Bold',
70+
71+
// UI4 palette
72+
teal: 'rgb(22, 50, 58)'
7073
}
7174

7275
const deviceWidth = Dimensions.get('window').width
@@ -394,5 +397,8 @@ export const edgeDark: Theme = {
394397
guiPluginLogoMoonpay: guiPluginLogoMoonpay,
395398

396399
// UI 4.0:
400+
cardBackgroundUi4: palette.teal,
401+
cardRadiusRemUi4: 1,
402+
397403
touchHighlightUi4: palette.lightGrayOp75
398404
}

‎src/theme/variables/edgeLight.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,5 +394,8 @@ export const edgeLight: Theme = {
394394
guiPluginLogoMoonpay: guiPluginLogoMoonpay,
395395

396396
// UI 4.0:
397+
cardBackgroundUi4: palette.mutedGray,
398+
cardRadiusRemUi4: 1,
399+
397400
touchHighlightUi4: palette.lightGrayOp75
398401
}

‎src/theme/variables/testDark.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,13 @@ const palette = {
7070
QuicksandRegular: 'Quicksand-Regular',
7171
QuicksandMedium: 'Quicksand-Medium',
7272
QuicksandSemiBold: 'Quicksand-SemiBold',
73-
QuicksandBold: 'Quicksand-Bold'
73+
QuicksandBold: 'Quicksand-Bold',
74+
75+
// UI4 palette
76+
darkTeal: 'rgb(0,35,45)',
77+
veryDarkTeal: 'rgb(10, 13, 15)',
78+
79+
teal: 'rgb(22, 50, 58)'
7480
}
7581

7682
const deviceWidth = Dimensions.get('window').width
@@ -408,5 +414,8 @@ export const testDark: Theme = {
408414
guiPluginLogoMoonpay: guiPluginLogoMoonpay,
409415

410416
// UI 4.0:
417+
cardBackgroundUi4: palette.teal,
418+
cardRadiusRemUi4: 1,
419+
411420
touchHighlightUi4: palette.lightGrayOp75
412421
}

‎src/types/Theme.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,5 +394,8 @@ export interface Theme {
394394
guiPluginLogoMoonpay: ImageProp
395395

396396
// UI 4.0:
397+
cardBackgroundUi4: string
398+
cardRadiusRemUi4: number
399+
397400
touchHighlightUi4: string
398401
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /