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

chore: update discover dapp and dapp filter styles #5625

Merged
merged 7 commits into from
Jul 10, 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
6 changes: 4 additions & 2 deletions src/components/FilterChipsCarousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ function FilterChipsCarousel<T>({
scrollEnabled={scrollEnabled}
showsHorizontalScrollIndicator={false}
style={[styles.container, style]}
contentContainerStyle={[styles.contentContainer, { width: scrollEnabled ? 'auto' : '100%' }]}
contentContainerStyle={[
styles.contentContainer,
{ flexWrap: scrollEnabled ? 'nowrap' : 'wrap', width: scrollEnabled ? 'auto' : '100%' },
]}
ref={forwardedRef}
testID="FilterChipsCarousel"
>
Expand Down Expand Up @@ -108,7 +111,6 @@ const styles = StyleSheet.create({
contentContainer: {
paddingHorizontal: Spacing.Thick24,
gap: Spacing.Smallest8,
flexWrap: 'wrap',
},
filterChipBackground: {
overflow: 'hidden',
Expand Down
4 changes: 4 additions & 0 deletions src/dapps/DappsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ function DappsScreen({ navigation }: Props) {
onFavoriteDapp={onFavoriteDapp}
showBorder={true}
testID={`${section.testID}/DappCard`}
cardStyle={styles.dappCard}
/>
)
}}
Expand Down Expand Up @@ -362,6 +363,9 @@ const styles = StyleSheet.create({
color: Colors.black,
marginBottom: Spacing.Thick24,
},
dappCard: {
marginTop: Spacing.Regular16,
},
})

export default DappsScreen
32 changes: 15 additions & 17 deletions src/dappsExplorer/DappCard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { Image, StyleSheet, Text, View } from 'react-native'
import { Image, StyleSheet, Text, View, ViewStyle } from 'react-native'
import { DappExplorerEvents } from 'src/analytics/Events'
import ValoraAnalytics from 'src/analytics/ValoraAnalytics'
import Card from 'src/components/Card'
Expand All @@ -20,7 +20,6 @@ interface DappCardContentProps {
onFavoriteDapp?: (dapp: Dapp) => void
favoritedFromSection: DappSection
disableFavoriting?: boolean
showBorder?: boolean
}

interface Props {
Expand All @@ -30,6 +29,8 @@ interface Props {
disableFavoriting?: boolean
onFavoriteDapp?: (dapp: Dapp) => void
showBorder?: boolean
cardContentContainerStyle?: ViewStyle
cardStyle?: ViewStyle
}

// Since this icon exists within a touchable, make the hitslop bigger than usual
Expand All @@ -40,7 +41,6 @@ export function DappCardContent({
onFavoriteDapp,
favoritedFromSection,
disableFavoriting,
showBorder,
}: DappCardContentProps) {
const dispatch = useDispatch()
const favoriteDappIds = useSelector(favoriteDappIdsSelector)
Expand All @@ -67,14 +67,7 @@ export function DappCardContent({
vibrateSuccess()
}
return (
<View
style={[
styles.pressableCard,
{
paddingHorizontal: showBorder ? Spacing.Regular16 : Spacing.Smallest8,
},
]}
>
<>
<Image source={{ uri: dapp.iconUrl }} style={styles.dappIcon} />
<View style={styles.itemTextContainer}>
<Text style={styles.title}>{dapp.name}</Text>
Expand All @@ -88,7 +81,7 @@ export function DappCardContent({
>
{isFavorited ? <Star /> : !disableFavoriting ? <StarOutline /> : <></>}
</Touchable>
</View>
</>
)
}

Expand All @@ -98,22 +91,28 @@ function DappCard({
onFavoriteDapp,
disableFavoriting,
showBorder,
cardContentContainerStyle,
cardStyle,
testID,
}: Props) {
return (
<Card
testID={testID}
style={[styles.card, showBorder ? styles.borderStyle : {}]}
style={[styles.card, showBorder ? styles.borderStyle : {}, cardStyle]}
rounded={true}
shadow={null}
>
<Touchable onPress={onPressDapp} borderRadius={8} testID={`Dapp/${dapp.id}`}>
<Touchable
style={[styles.pressableCard, cardContentContainerStyle]}
onPress={onPressDapp}
borderRadius={showBorder ? 8 : undefined}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can 8 be Spacing.Smallest8?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i prefer not to 🙈 i agree that we prefer variables over hardcoded numbers so that we are restricted to certain consistent values + it's easier to make a global change for the values, but i think borders and spaces may not want to use the same variables...it can be a surprise if a change to "Spacing" values also changes rounded corners. i've always wanted to create a separate style enum for borders but never got round to it 😅

testID={`Dapp/${dapp.id}`}
>
<DappCardContent
dapp={dapp}
onFavoriteDapp={onFavoriteDapp}
disableFavoriting={disableFavoriting}
favoritedFromSection={DappSection.All}
showBorder={showBorder}
/>
</Touchable>
</Card>
Expand All @@ -139,10 +138,9 @@ const styles = StyleSheet.create({
flexDirection: 'row',
alignItems: 'center',
flex: 1,
paddingVertical: Spacing.Regular16,
padding: Spacing.Regular16,
},
card: {
marginTop: Spacing.Regular16,
padding: 0,
},
title: {
Expand Down
69 changes: 26 additions & 43 deletions src/dappsExplorer/DiscoverDappsCard.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import React, { useEffect, useMemo, useRef } from 'react'
import { useTranslation } from 'react-i18next'
import { SectionList, StyleSheet, Text, View } from 'react-native'
import { useSafeAreaInsets } from 'react-native-safe-area-context'
import { DappExplorerEvents } from 'src/analytics/Events'
import ValoraAnalytics from 'src/analytics/ValoraAnalytics'
import { mostPopularDappsSelector, favoriteDappsSelector } from 'src/dapps/selectors'
import TextButton from 'src/components/TextButton'
import { favoriteDappsSelector, mostPopularDappsSelector } from 'src/dapps/selectors'
import { fetchDappsList } from 'src/dapps/slice'
import { ActiveDapp, Dapp, DappSection } from 'src/dapps/types'
import DappCard from 'src/dappsExplorer/DappCard'
import useOpenDapp from 'src/dappsExplorer/useOpenDapp'
import { currentLanguageSelector } from 'src/i18n/selectors'
import { navigate } from 'src/navigator/NavigationService'
import { Screens } from 'src/navigator/Screens'
import { useDispatch, useSelector } from 'src/redux/hooks'
import { Colors } from 'src/styles/colors'
import fontStyles, { typeScale } from 'src/styles/fonts'
import { typeScale } from 'src/styles/fonts'
import { Spacing } from 'src/styles/styles'
import TextButton from 'src/components/TextButton'
import { navigate } from 'src/navigator/NavigationService'

interface SectionData {
data: Dapp[]
Expand All @@ -30,11 +28,8 @@ const MAX_DAPPS = 5
function DiscoverDappsCard() {
const { t } = useTranslation()

const insets = useSafeAreaInsets()

const sectionListRef = useRef<SectionList>(null)

const language = useSelector(currentLanguageSelector)
const dispatch = useDispatch()
const favoriteDapps = useSelector(favoriteDappsSelector)
const mostPopularDapps = useSelector(mostPopularDappsSelector)
Expand Down Expand Up @@ -62,7 +57,7 @@ function DiscoverDappsCard() {
data: mostPopularDapps
.filter((dapp) => !favoriteDappIds.includes(dapp.id))
.slice(0, MAX_DAPPS - favoriteDapps.length),
sectionName: t('dappsScreen.mostPopularDapps').toLocaleUpperCase(language ?? 'en-US'),
sectionName: t('dappsScreen.mostPopularDapps'),
dappSection: DappSection.MostPopular,
testID: 'DiscoverDappsCard/MostPopularSection',
},
Expand All @@ -73,7 +68,7 @@ function DiscoverDappsCard() {
? [
{
data: favoriteDapps.slice(0, MAX_DAPPS),
sectionName: t('dappsScreen.favoriteDapps').toLocaleUpperCase(language ?? 'en-US'),
sectionName: t('dappsScreen.favoriteDapps'),
dappSection: DappSection.FavoritesDappScreen,
testID: 'DiscoverDappsCard/FavoritesSection',
},
Expand All @@ -97,25 +92,22 @@ function DiscoverDappsCard() {
scrollEnabled={false}
ListHeaderComponent={<Text style={styles.title}>{t('dappsScreen.exploreDapps')}</Text>}
ListFooterComponent={
<TextButton style={styles.footer} onPress={onPressExploreAll}>
{t('dappsScreen.exploreAll')}
</TextButton>
<View>
<TextButton style={styles.footer} onPress={onPressExploreAll}>
{t('dappsScreen.exploreAll')}
</TextButton>
</View>
}
contentContainerStyle={[
styles.sectionListContentContainer,
{ paddingBottom: Math.max(insets.bottom, Spacing.Regular16) },
]}
sections={sections}
renderItem={({ item: dapp, index, section }) => {
return (
<View style={styles.cardContainer}>
<DappCard
dapp={dapp}
onPressDapp={() => onPressDapp({ ...dapp, openedFrom: section.dappSection }, index)}
disableFavoriting={true}
testID={`${section.testID}/DappCard`}
/>
</View>
<DappCard
dapp={dapp}
onPressDapp={() => onPressDapp({ ...dapp, openedFrom: section.dappSection }, index)}
disableFavoriting={true}
testID={`${section.testID}/DappCard`}
cardContentContainerStyle={styles.dappCardContentContainer}
/>
)
}}
renderSectionHeader={({ section: { sectionName, testID } }) => {
Expand All @@ -139,40 +131,31 @@ function DiscoverDappsCard() {
const styles = StyleSheet.create({
container: {
padding: Spacing.Regular16,
paddingBottom: 0,
gap: Spacing.Smallest8,
borderColor: Colors.gray2,
borderWidth: 1,
borderRadius: Spacing.Smallest8,
},
sectionListContentContainer: {
paddingTop: Spacing.Regular16,
flexGrow: 1,
},
sectionTitle: {
...fontStyles.label,
paddingTop: Spacing.Small12,
paddingLeft: Spacing.Regular16,
...typeScale.labelXSmall,
color: Colors.gray4,
marginTop: Spacing.Smallest8,
},
listFooterComponent: {
flex: 1,
alignItems: 'center',
paddingTop: Spacing.Regular16,
alignSelf: 'center',
},
footer: {
...typeScale.labelSemiBoldXSmall,
flex: 1,
color: Colors.primary,
},
title: {
...typeScale.titleMedium,
...typeScale.labelSemiBoldMedium,
color: Colors.black,
marginBottom: Spacing.Large32,
paddingLeft: Spacing.Regular16,
marginBottom: Spacing.Smallest8,
},
cardContainer: {
paddingLeft: Spacing.Smallest8,
dappCardContentContainer: {
padding: 0,
marginVertical: Spacing.Regular16,
},
})

Expand Down