Skip to content

Commit

Permalink
1233: Implement lists as actual list (#2521)
Browse files Browse the repository at this point in the history
* 1233: Implement lists as actual list

* 1233: ts error

* 1233: linting error is resolved

* 1233: additional changes to accessibility

* 1233: improved accessibility on native and web

* 1233: Removed some unnessary props and renamed the file

* 1233: implemented suggestion related to prop

* 1233: added pluralization and implemented suggestions

* 1233: added translation and implemented suggestions
  • Loading branch information
lunars97 authored Dec 6, 2023
1 parent 8f5cf57 commit 65b07ca
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 21 deletions.
26 changes: 17 additions & 9 deletions native/src/components/Categories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import TileModel from '../models/TileModel'
import testID from '../testing/testID'
import { LanguageResourceCacheStateType, PageResourceCacheStateType } from '../utils/DataContainer'
import CategoryListItem from './CategoryListItem'
import List from './List'
import OrganizationContentInfo from './OrganizationContentInfo'
import Page from './Page'
import Tiles from './Tiles'
Expand Down Expand Up @@ -80,16 +81,23 @@ const Categories = ({
language={language}
path={category.path}
AfterContent={category.organization && <OrganizationContentInfo organization={category.organization} />}
Footer={children.map(it => (
<CategoryListItem
key={it.path}
category={it}
subCategories={categories.getChildren(it)}
resourceCache={resourceCache}
language={language}
onItemPress={navigateToCategory}
Footer={
<List
items={children}
renderItem={({ item: it }) => (
<CategoryListItem
key={it.path}
category={it}
subCategories={categories.getChildren(it)}
resourceCache={resourceCache}
language={language}
onItemPress={navigateToCategory}
/>
)}
// Fixes VirtualizedLists nesting error
scrollEnabled={false}
/>
))}
}
/>
)
}
Expand Down
23 changes: 14 additions & 9 deletions native/src/components/CategoryListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { contentDirection, isContentDirectionReversalRequired } from '../constan
import dimensions from '../constants/dimensions'
import { LanguageResourceCacheStateType } from '../utils/DataContainer'
import { getCachedThumbnail } from './Categories'
import List from './List'
import SimpleImage from './SimpleImage'
import SubCategoryListItem from './SubCategoryListItem'
import Pressable from './base/Pressable'
Expand Down Expand Up @@ -82,15 +83,19 @@ const CategoryListItem = ({
</CategoryEntryContainer>
</DirectionContainer>
</FlexStyledLink>
{subCategories.map(subCategory => (
<SubCategoryListItem
key={subCategory.path}
subCategory={subCategory}
resourceCache={resourceCache[subCategory.path] ?? {}}
onItemPress={onItemPress}
language={language}
/>
))}
<List
items={subCategories}
renderItem={({ item: subCategory }) => (
<SubCategoryListItem
key={subCategory.path}
subCategory={subCategory}
resourceCache={resourceCache[subCategory.path] ?? {}}
onItemPress={onItemPress}
language={language}
/>
)}
scrollEnabled={false}
/>
</>
)

Expand Down
3 changes: 3 additions & 0 deletions native/src/components/LayoutedScrollView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const LayoutedScrollView = (props: LayoutedScrollViewProps): ReactElement => {
<Layout>
<ScrollView
keyboardShouldPersistTaps='always'
// Fixes VirtualizedLists nesting error
// See https://github.com/facebook/react-native/issues/31697#issuecomment-1742437232
nestedScrollEnabled
refreshControl={refreshControl}
contentContainerStyle={{
flexGrow: 1,
Expand Down
9 changes: 8 additions & 1 deletion native/src/components/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ const NoItemsMessage = styled.Text`

type ListProps<T> = {
items: Array<T>
noItemsMessage: ReactElement | string
noItemsMessage?: ReactElement | string
renderItem: (props: { item: T; index: number }) => ReactElement
Header?: ReactElement
Footer?: ReactElement
scrollEnabled?: boolean
accessibilityLabel?: string
refresh?: () => void
onEndReached?: () => void
}
Expand All @@ -26,7 +28,9 @@ const List = <T,>({
Header,
Footer,
refresh,
accessibilityLabel,
onEndReached,
scrollEnabled,
}: ListProps<T>): ReactElement => (
<FlatList
data={items}
Expand All @@ -46,6 +50,9 @@ const List = <T,>({
paddingHorizontal: 10,
}}
onEndReachedThreshold={1}
scrollEnabled={scrollEnabled}
accessibilityRole='list'
accessibilityLabel={accessibilityLabel}
/>
)

Expand Down
4 changes: 3 additions & 1 deletion native/src/components/SearchListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { memo, ReactElement } from 'react'
import { useTranslation } from 'react-i18next'
import Highlighter from 'react-native-highlight-words'
import styled, { useTheme } from 'styled-components/native'

Expand Down Expand Up @@ -58,6 +59,7 @@ const SearchListItem = ({
onItemPress,
query,
}: SearchListItemProps): ReactElement => {
const { t } = useTranslation('search')
const theme = useTheme()
const { title, thumbnail } = category
const excerpt = getExcerpt(contentWithoutHtml, { query, maxChars: SEARCH_PREVIEW_MAX_CHARS })
Expand Down Expand Up @@ -86,7 +88,7 @@ const SearchListItem = ({
/>
)
return (
<FlexStyledLink onPress={() => onItemPress(category)}>
<FlexStyledLink onPress={() => onItemPress(category)} accessibilityHint={t('itemHint')}>
<DirectionContainer language={language}>
<SearchEntryContainer>
<TitleDirectionContainer language={language}>
Expand Down
7 changes: 6 additions & 1 deletion native/src/components/base/TextButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ type TextButtonProps = {
}

const TextButton = ({ text, onPress, disabled = false, type = 'primary', style }: TextButtonProps): ReactElement => (
<StyledPressable onPress={onPress} primary={type === 'primary'} disabled={disabled} style={style}>
<StyledPressable
onPress={onPress}
primary={type === 'primary'}
disabled={disabled}
style={style}
accessibilityRole='button'>
<StyledText>{text}</StyledText>
</StyledPressable>
)
Expand Down
1 change: 1 addition & 0 deletions native/src/routes/SearchModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ const SearchModal = ({
<List
items={searchResults}
renderItem={renderItem}
accessibilityLabel={t('searchResultsCount', { count: searchResults.length })}
noItemsMessage={
<>
<NothingFound />
Expand Down
14 changes: 14 additions & 0 deletions translations/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -8412,6 +8412,13 @@
"de": {
"nothingFound": "Es wurden leider keine passenden Ergebnisse gefunden.",
"searchPlaceholder": "Suche",
"itemHint": "Suchergebnis öffnen",
"searchResultsCount_zero": "0 Suchergebnisse",
"searchResultsCount_one": "1 Suchergebnis",
"searchResultsCount_two": "2 Suchergebnisse",
"searchResultsCount_few": "{{count}} Suchergebnisse",
"searchResultsCount_many": "{{count}} Suchergebnisse",
"searchResultsCount_other": "{{count}} Suchergebnisse",
"pageTitle": "Suche",
"delete": "Eingabe löschen"
},
Expand Down Expand Up @@ -8454,6 +8461,13 @@
"en": {
"nothingFound": "Sorry, we could not find any matching results.",
"searchPlaceholder": "Search",
"itemHint": "View search result",
"searchResultsCount_zero": "0 search results",
"searchResultsCount_one": "1 search result",
"searchResultsCount_two": "2 search results",
"searchResultsCount_few": "{{count}} search results",
"searchResultsCount_many": "{{count}} search results",
"searchResultsCount_other": "{{count}} search results",
"pageTitle": "Search",
"delete": "Delete input"
},
Expand Down

0 comments on commit 65b07ca

Please sign in to comment.