Skip to content

Commit f4776f1

Browse files
authored
Add letterListContainerStyle prop (#27)
1 parent 134b655 commit f4776f1

File tree

6 files changed

+42
-5
lines changed

6 files changed

+42
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ render() {
100100
| `getItemHeight` (optional) | For [`sectionListGetItemLayout`](https://www.npmjs.com/package/react-native-section-list-get-item-layout). This may be necessary if each item has a dynamic height. This allows for smooth scrolling and accurate positioning when scrolling to a section. | `func` | `{ sectionIndex: number, rowIndex: number } : number` | |
101101
| `sectionHeaderHeight` (optional) | The height of the section header. | `number` | | `40` |
102102
| `listHeaderHeight` (optional) | The height of the list header. | `number` | | `0` |
103+
| `letterListContainerStyle` (optional) | Override the style of the letter list container. | `object` | | `undefined` |
103104
| `indexContainerStyle` (optional) | Override the style of the list index container. | `object` | | `undefined` |
104105
| `indexLetterStyle` (optional) | Override the style of the list letter index text. | `object` | | `undefined` |
105106
| `indexLetterContainerStyle` (optional) | Override the style of the list letter index container. | `object` | | `undefined` |

src/components/AlphabetList/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const AlphabetList: React.FC<AlphabetListProps> = (props) => {
1717
indexContainerStyle,
1818
indexLetterStyle,
1919
indexLetterContainerStyle,
20+
letterListContainerStyle,
2021
getItemHeight: onGetItemHeight = () => sizes.itemHeight,
2122
sectionHeaderHeight = sizes.itemHeight,
2223
listHeaderHeight = sizes.listHeaderHeight,
@@ -96,6 +97,7 @@ export const AlphabetList: React.FC<AlphabetListProps> = (props) => {
9697
indexContainerStyle={indexContainerStyle}
9798
indexLetterStyle={indexLetterStyle}
9899
indexLetterContainerStyle={indexLetterContainerStyle}
100+
letterListContainerStyle={letterListContainerStyle}
99101
renderCustomIndexLetter={renderCustomIndexLetter}
100102
/>
101103
</View>

src/components/AlphabetList/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface AlphabetListProps extends Partial<SectionListProps<IData>> {
2323
indexLetterStyle?: TextStyle,
2424
indexLetterContainerStyle?: ViewStyle,
2525
indexContainerStyle?: ViewStyle,
26+
letterListContainerStyle?: ViewStyle,
2627
renderCustomItem?: (item: IData) => JSX.Element;
2728
renderCustomSectionHeader?: (section: SectionListData<IData>) => JSX.Element;
2829
renderCustomListHeader?: () => JSX.Element;

src/components/ListLetterIndex/index.test.tsx

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { ListLetterIndex } from "."
33
import { render, fireEvent } from '@testing-library/react-native';
4-
import { View, Text } from "react-native"
4+
import { View, Text, ViewStyle } from "react-native"
55

66
describe('ListLetterIndex', () => {
77
const mockPressLetterFn = jest.fn()
@@ -154,5 +154,35 @@ describe('ListLetterIndex', () => {
154154
expect(indexItemLabelElements[0].props.style).toEqual(expectedStyle)
155155
})
156156

157+
it('letterListContainerStyle > should apply custom style', () => {
158+
// Arrange.
159+
const letterListContainerStyle : ViewStyle = {
160+
alignItems: "flex-start",
161+
}
162+
163+
const expectedStyle = [
164+
{
165+
alignItems: "center",
166+
justifyContent: "center",
167+
height: "100%",
168+
},
169+
{
170+
alignItems: "flex-start"
171+
}
172+
]
173+
174+
const { getAllByTestId } = render(
175+
<ListLetterIndex
176+
sectionData={sectionData}
177+
onPressLetter={mockPressLetterFn}
178+
letterListContainerStyle={letterListContainerStyle}
179+
/>
180+
)
181+
182+
const flatList = getAllByTestId("flatList");
183+
184+
// Assert.
185+
expect(flatList[0].props.contentContainerStyle).toEqual(expectedStyle)
186+
})
157187

158-
})
188+
})

src/components/ListLetterIndex/index.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export const ListLetterIndex: React.FC<ListLetterIndexProps> = ({
1010
indexContainerStyle,
1111
indexLetterStyle,
1212
indexLetterContainerStyle,
13-
renderCustomIndexLetter
13+
renderCustomIndexLetter,
14+
letterListContainerStyle
1415
}) => {
1516
const onRenderCustomIndexLetter = ({ item, index }: { item: ISectionData, index: number }) => {
1617
const onPress = () => onPressLetter(index)
@@ -35,11 +36,12 @@ export const ListLetterIndex: React.FC<ListLetterIndexProps> = ({
3536
return (
3637
<View style={[styles.letterIndexContainer, indexContainerStyle]}>
3738
<FlatList
38-
contentContainerStyle={styles.letterIndexList}
39+
testID="flatList"
40+
contentContainerStyle={[styles.letterIndexList, letterListContainerStyle]}
3941
data={sectionData}
4042
keyExtractor={(i) => i.title}
4143
renderItem={onRenderCustomIndexLetter}
4244
/>
4345
</View>
4446
)
45-
}
47+
}

src/components/ListLetterIndex/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ export interface ListLetterIndexProps {
77
indexLetterStyle?: AlphabetListProps["indexLetterStyle"],
88
indexLetterContainerStyle?: AlphabetListProps["indexLetterContainerStyle"],
99
renderCustomIndexLetter?: AlphabetListProps["renderCustomIndexLetter"],
10+
letterListContainerStyle?: AlphabetListProps["letterListContainerStyle"]
1011
}

0 commit comments

Comments
 (0)