MCPcopy Create free account
hub / github.com/Kureev/react-native-list / _subExtractor

Method _subExtractor

VirtualizedSectionList.js:166–200  ·  view source on GitHub ↗
(
    index: number,
  )

Source from the content-addressed store, hash-verified

164 };
165
166 _subExtractor(
167 index: number,
168 ): ?{
169 section: SectionT,
170 key: string, // Key of the section or combined key for section + item
171 index: ?number, // Relative index within the section
172 leadingItem?: ?Item,
173 leadingSection?: ?SectionT,
174 trailingItem?: ?Item,
175 trailingSection?: ?SectionT,
176 } {
177 let itemIndex = index;
178 const defaultKeyExtractor = this.props.keyExtractor;
179 for (let ii = 0; ii < this.props.sections.length; ii++) {
180 const section = this.props.sections[ii];
181 const key = section.key || String(ii);
182 itemIndex -= 1; // The section itself is an item
183 if (itemIndex >= section.data.length) {
184 itemIndex -= section.data.length;
185 } else if (itemIndex === -1) {
186 return {section, key, index: null, trailingSection: this.props.sections[ii + 1]};
187 } else {
188 const keyExtractor = section.keyExtractor || defaultKeyExtractor;
189 return {
190 section,
191 key: key + ':' + keyExtractor(section.data[itemIndex], itemIndex),
192 index: itemIndex,
193 leadingItem: section.data[itemIndex - 1],
194 leadingSection: this.props.sections[ii - 1],
195 trailingItem: section.data[itemIndex + 1],
196 trailingSection: this.props.sections[ii + 1],
197 };
198 }
199 }
200 }
201
202 _convertViewable = (viewable: ViewToken): ?ViewToken => {
203 invariant(viewable.index != null, 'Received a broken ViewToken');

Callers 2

Calls

no outgoing calls

Tested by

no test coverage detected