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

Change many border widths from 1 to hairlineWidth #4294

Merged
merged 30 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
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
13 changes: 7 additions & 6 deletions src/alf/atoms.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {Platform} from 'react-native'
import {Platform, StyleSheet} from 'react-native'

import * as tokens from '#/alf/tokens'
import {native, web} from '#/alf/util/platform'
import hairlineWidth = StyleSheet.hairlineWidth

export const atoms = {
/*
Expand Down Expand Up @@ -277,19 +278,19 @@ export const atoms = {
borderWidth: 0,
},
border: {
borderWidth: 1,
borderWidth: hairlineWidth,
},
border_t: {
borderTopWidth: 1,
borderTopWidth: hairlineWidth,
},
border_b: {
borderBottomWidth: 1,
borderBottomWidth: hairlineWidth,
},
border_l: {
borderLeftWidth: 1,
borderLeftWidth: hairlineWidth,
},
border_r: {
borderRightWidth: 1,
borderRightWidth: hairlineWidth,
},

/*
Expand Down
4 changes: 2 additions & 2 deletions src/components/AccountList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function AccountList({
style={[
a.rounded_md,
a.overflow_hidden,
a.border,
{borderWidth: 1},
t.atoms.border_contrast_low,
]}>
{accounts.map(account => (
Expand All @@ -48,7 +48,7 @@ export function AccountList({
isCurrentAccount={account.did === currentAccount?.did}
isPendingAccount={account.did === pendingDid}
/>
<View style={[a.border_b, t.atoms.border_contrast_low]} />
<View style={[{borderBottomWidth: 1}, t.atoms.border_contrast_low]} />
</React.Fragment>
))}
<Button
Expand Down
5 changes: 3 additions & 2 deletions src/view/com/composer/Composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ import {SuggestedLanguage} from './select-language/SuggestedLanguage'
import {TextInput, TextInputRef} from './text-input/TextInput'
import {ThreadgateBtn} from './threadgate/ThreadgateBtn'
import {useExternalLinkFetch} from './useExternalLinkFetch'
import hairlineWidth = StyleSheet.hairlineWidth

type CancelRef = {
onPressCancel: () => void
Expand Down Expand Up @@ -657,7 +658,7 @@ const styles = StyleSheet.create({
marginBottom: 6,
},
errorIcon: {
borderWidth: 1,
borderWidth: hairlineWidth,
borderColor: colors.red4,
color: colors.red4,
borderRadius: 30,
Expand Down Expand Up @@ -692,6 +693,6 @@ const styles = StyleSheet.create({
paddingLeft: 15,
paddingRight: 20,
alignItems: 'center',
borderTopWidth: 1,
borderTopWidth: hairlineWidth,
},
})
16 changes: 9 additions & 7 deletions src/view/com/composer/Prompt.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React from 'react'
import {StyleSheet, TouchableOpacity} from 'react-native'
import {UserAvatar} from '../util/UserAvatar'
import {Text} from '../util/text/Text'
import {usePalette} from 'lib/hooks/usePalette'
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
import {Trans, msg} from '@lingui/macro'
import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react'
import {useSession} from '#/state/session'

import {useProfileQuery} from '#/state/queries/profile'
import {useSession} from '#/state/session'
import {usePalette} from 'lib/hooks/usePalette'
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
import {Text} from '../util/text/Text'
import {UserAvatar} from '../util/UserAvatar'
import hairlineWidth = StyleSheet.hairlineWidth

export function ComposePrompt({onPressCompose}: {onPressCompose: () => void}) {
const {currentAccount} = useSession()
Expand Down Expand Up @@ -47,7 +49,7 @@ const styles = StyleSheet.create({
paddingBottom: 10,
flexDirection: 'row',
alignItems: 'center',
borderTopWidth: 1,
borderTopWidth: hairlineWidth,
},
labelMobile: {
paddingLeft: 12,
Expand Down
16 changes: 13 additions & 3 deletions src/view/com/feeds/FeedSourceCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import * as Prompt from '#/components/Prompt'
import {RichText} from '#/components/RichText'
import {Text} from '../util/text/Text'
import {UserAvatar} from '../util/UserAvatar'
import hairlineWidth = StyleSheet.hairlineWidth

export function FeedSourceCard({
feedUri,
Expand All @@ -34,6 +35,7 @@ export function FeedSourceCard({
showLikes = false,
pinOnSave = false,
showMinimalPlaceholder,
hideTopBorder,
}: {
feedUri: string
style?: StyleProp<ViewStyle>
Expand All @@ -42,6 +44,7 @@ export function FeedSourceCard({
showLikes?: boolean
pinOnSave?: boolean
showMinimalPlaceholder?: boolean
hideTopBorder?: boolean
}) {
const {data: preferences} = usePreferencesQuery()
const {data: feed} = useFeedSourceInfoQuery({uri: feedUri})
Expand All @@ -57,6 +60,7 @@ export function FeedSourceCard({
showLikes={showLikes}
pinOnSave={pinOnSave}
showMinimalPlaceholder={showMinimalPlaceholder}
hideTopBorder={hideTopBorder}
/>
)
}
Expand All @@ -71,6 +75,7 @@ export function FeedSourceCardLoaded({
showLikes = false,
pinOnSave = false,
showMinimalPlaceholder,
hideTopBorder,
}: {
feedUri: string
feed?: FeedSourceInfo
Expand All @@ -81,6 +86,7 @@ export function FeedSourceCardLoaded({
showLikes?: boolean
pinOnSave?: boolean
showMinimalPlaceholder?: boolean
hideTopBorder?: boolean
}) {
const t = useTheme()
const pal = usePalette('default')
Expand Down Expand Up @@ -149,7 +155,7 @@ export function FeedSourceCardLoaded({
style={[
pal.border,
{
borderTopWidth: showMinimalPlaceholder ? 0 : 1,
borderTopWidth: showMinimalPlaceholder || hideTopBorder ? 0 : 1,
flexDirection: 'row',
alignItems: 'center',
flex: 1,
Expand Down Expand Up @@ -191,7 +197,12 @@ export function FeedSourceCardLoaded({
<Pressable
testID={`feed-${feed.displayName}`}
accessibilityRole="button"
style={[styles.container, pal.border, style]}
style={[
styles.container,
pal.border,
style,
{borderTopWidth: hideTopBorder ? 0 : hairlineWidth},
]}
onPress={() => {
if (feed.type === 'feed') {
navigation.push('ProfileFeed', {
Expand Down Expand Up @@ -295,7 +306,6 @@ const styles = StyleSheet.create({
paddingVertical: 20,
flexDirection: 'column',
flex: 1,
borderTopWidth: 1,
gap: 14,
},
headerContainer: {
Expand Down
4 changes: 3 additions & 1 deletion src/view/com/feeds/ProfileFeedgens.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'
import {
findNodeHandle,
ListRenderItemInfo,
StyleProp,
StyleSheet,
View,
Expand Down Expand Up @@ -134,7 +135,7 @@ export const ProfileFeedgens = React.forwardRef<
// =

const renderItemInner = React.useCallback(
({item}: {item: any}) => {
({item, index}: ListRenderItemInfo<any>) => {
if (item === EMPTY) {
return (
<View
Expand Down Expand Up @@ -169,6 +170,7 @@ export const ProfileFeedgens = React.forwardRef<
preferences={preferences}
style={styles.item}
showLikes
hideTopBorder={index === 0}
/>
)
}
Expand Down
22 changes: 12 additions & 10 deletions src/view/com/lists/ListCard.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import React from 'react'
import {StyleProp, StyleSheet, View, ViewStyle} from 'react-native'
import {AtUri, AppBskyGraphDefs, RichText} from '@atproto/api'
import {Link} from '../util/Link'
import {Text} from '../util/text/Text'
import {RichText as RichTextCom} from '#/components/RichText'
import {UserAvatar} from '../util/UserAvatar'
import {s} from 'lib/styles'
import {usePalette} from 'lib/hooks/usePalette'
import {AppBskyGraphDefs, AtUri, RichText} from '@atproto/api'
import {Trans} from '@lingui/macro'

import {useSession} from '#/state/session'
import {usePalette} from 'lib/hooks/usePalette'
import {makeProfileLink} from 'lib/routes/links'
import {sanitizeDisplayName} from 'lib/strings/display-names'
import {sanitizeHandle} from 'lib/strings/handles'
import {makeProfileLink} from 'lib/routes/links'
import {Trans} from '@lingui/macro'
import {s} from 'lib/styles'
import {atoms as a} from '#/alf'
import {RichText as RichTextCom} from '#/components/RichText'
import {Link} from '../util/Link'
import {Text} from '../util/text/Text'
import {UserAvatar} from '../util/UserAvatar'
import hairlineWidth = StyleSheet.hairlineWidth

export const ListCard = ({
testID,
Expand Down Expand Up @@ -132,7 +134,7 @@ export const ListCard = ({

const styles = StyleSheet.create({
outer: {
borderTopWidth: 1,
borderTopWidth: hairlineWidth,
paddingHorizontal: 6,
},
outerNoBorder: {
Expand Down
18 changes: 10 additions & 8 deletions src/view/com/lists/MyLists.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ import {
ViewStyle,
} from 'react-native'
import {AppBskyGraphDefs as GraphDefs} from '@atproto/api'
import {ListCard} from './ListCard'
import {Trans} from '@lingui/macro'

import {cleanError} from '#/lib/strings/errors'
import {logger} from '#/logger'
import {MyListsFilter, useMyListsQuery} from '#/state/queries/my-lists'
import {ErrorMessage} from '../util/error/ErrorMessage'
import {Text} from '../util/text/Text'
import {useAnalytics} from 'lib/analytics/analytics'
import {usePalette} from 'lib/hooks/usePalette'
import {List} from '../util/List'
import {s} from 'lib/styles'
import {logger} from '#/logger'
import {Trans} from '@lingui/macro'
import {cleanError} from '#/lib/strings/errors'
import {ErrorMessage} from '../util/error/ErrorMessage'
import {List} from '../util/List'
import {Text} from '../util/text/Text'
import {ListCard} from './ListCard'
import hairlineWidth = StyleSheet.hairlineWidth

const LOADING = {_reactKey: '__loading__'}
const EMPTY = {_reactKey: '__empty__'}
Expand Down Expand Up @@ -84,7 +86,7 @@ export function MyLists({
<View
key={item._reactKey}
testID="listsEmpty"
style={[{padding: 18, borderTopWidth: 1}, pal.border]}>
style={[{padding: 18, borderTopWidth: hairlineWidth}, pal.border]}>
<Text style={pal.textLight}>
<Trans>You have no lists.</Trans>
</Text>
Expand Down
8 changes: 4 additions & 4 deletions src/view/com/lists/ProfileLists.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'
import {
findNodeHandle,
ListRenderItemInfo,
StyleProp,
StyleSheet,
View,
Expand Down Expand Up @@ -138,12 +139,10 @@ export const ProfileLists = React.forwardRef<SectionRef, ProfileListsProps>(
// =

const renderItemInner = React.useCallback(
({item}: {item: any}) => {
({item, index}: ListRenderItemInfo<any>) => {
if (item === EMPTY) {
return (
<View
testID="listsEmpty"
style={[{padding: 18, borderTopWidth: 1}, pal.border]}>
<View testID="listsEmpty" style={[{padding: 18}, pal.border]}>
<Text style={pal.textLight}>
<Trans>You have no lists.</Trans>
</Text>
Expand Down Expand Up @@ -173,6 +172,7 @@ export const ProfileLists = React.forwardRef<SectionRef, ProfileListsProps>(
list={item}
testID={`list-${item.name}`}
style={styles.item}
noBorder={index === 0}
/>
)
},
Expand Down
33 changes: 24 additions & 9 deletions src/view/com/notifications/Feed.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import React from 'react'
import {ActivityIndicator, StyleSheet, View} from 'react-native'
import {
ActivityIndicator,
ListRenderItemInfo,
StyleSheet,
View,
} from 'react-native'
import {msg} from '@lingui/macro'
import {useLingui} from '@lingui/react'

Expand All @@ -17,6 +22,9 @@ import {NotificationFeedLoadingPlaceholder} from '../util/LoadingPlaceholder'
import {LoadMoreRetryBtn} from '../util/LoadMoreRetryBtn'
import {CenteredView} from '../util/Views'
import {FeedItem} from './FeedItem'
import hairlineWidth = StyleSheet.hairlineWidth
import {useInitialNumToRender} from 'lib/hooks/useInitialNumToRender'
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'

const EMPTY_FEED_ITEM = {_reactKey: '__empty__'}
const LOAD_MORE_ERROR_ITEM = {_reactKey: '__load_more_error__'}
Expand All @@ -33,8 +41,11 @@ export function Feed({
onScrolledDownChange: (isScrolledDown: boolean) => void
ListHeaderComponent?: () => JSX.Element
}) {
const initialNumToRender = useInitialNumToRender()

const [isPTRing, setIsPTRing] = React.useState(false)
const pal = usePalette('default')
const {isTabletOrMobile} = useWebMediaQueries()

const {_} = useLingui()
const moderationOpts = useModerationOpts()
Expand Down Expand Up @@ -97,12 +108,8 @@ export function Feed({
fetchNextPage()
}, [fetchNextPage])

// TODO optimize renderItem or FeedItem, we're getting this notice from RN: -prf
// VirtualizedList: You have a large list that is slow to update - make sure your
// renderItem function renders components that follow React performance best practices
// like PureComponent, shouldComponentUpdate, etc
const renderItem = React.useCallback(
({item}: {item: any}) => {
({item, index}: ListRenderItemInfo<any>) => {
if (item === EMPTY_FEED_ITEM) {
return (
<EmptyState
Expand All @@ -122,14 +129,20 @@ export function Feed({
)
} else if (item === LOADING_ITEM) {
return (
<View style={[pal.border, {borderTopWidth: 1}]}>
<View style={[pal.border, {borderTopWidth: hairlineWidth}]}>
<NotificationFeedLoadingPlaceholder />
</View>
)
}
return <FeedItem item={item} moderationOpts={moderationOpts!} />
return (
<FeedItem
item={item}
moderationOpts={moderationOpts!}
hideTopBorder={index === 0 && isTabletOrMobile}
/>
)
},
[onPressRetryLoadMore, moderationOpts, _, pal.border],
[moderationOpts, isTabletOrMobile, _, onPressRetryLoadMore, pal.border],
)

const FeedFooter = React.useCallback(
Expand Down Expand Up @@ -170,6 +183,8 @@ export function Feed({
contentContainerStyle={s.contentContainer}
// @ts-ignore our .web version only -prf
desktopFixedHeight
initialNumToRender={initialNumToRender}
windowSize={11}
Comment on lines +186 to +187
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We were missing some FlatList perf props here. Removed the above comment after adding this, since I wasn't even getting the warning previously anyway.

/>
</View>
)
Expand Down
Loading
Loading