MCPcopy
hub / github.com/callstack/react-native-paper / splitStyles

Function splitStyles

src/utils/splitStyles.ts:22–60  ·  view source on GitHub ↗
(
  styles: ViewStyle,
  ...filters: Tuple
)

Source from the content-addressed store, hash-verified

20 * - A style property will exist in a single style object, the first filter it matched
21 */
22export function splitStyles<Tuple extends FiltersArray>(
23 styles: ViewStyle,
24 ...filters: Tuple
25) {
26 if (process.env.NODE_ENV !== 'production' && filters.length === 0) {
27 console.error('No filters were passed when calling splitStyles');
28 }
29
30 // `Object.entries` will be used to iterate over the styles and `Object.fromEntries` will be called before returning
31 // Entries which match the given filters will be temporarily stored in `newStyles`
32 const newStyles = filters.map(() => [] as Entry[]);
33
34 // Entries which match no filter
35 const rest: Entry[] = [];
36
37 // Iterate every style property
38 outer: for (const item of Object.entries(styles) as Entry[]) {
39 // Check each filter
40 for (let i = 0; i < filters.length; i++) {
41 // Check if filter matches
42 if (filters[i](item[0])) {
43 newStyles[i].push(item); // Push to temporary filtered entries array
44 continue outer; // Skip to checking next style property
45 }
46 }
47
48 // Adds to rest styles if not filtered
49 rest.push(item);
50 }
51
52 // Put unmatched styles in the beginning
53 newStyles.unshift(rest);
54
55 // Convert arrays of entries into objects
56 return newStyles.map((styles) => Object.fromEntries(styles)) as unknown as [
57 ViewStyle,
58 ...MappedTuple<Tuple>
59 ];
60}

Callers 6

Surface.tsxFile · 0.90
ButtonFunction · 0.90
CardCoverFunction · 0.90
CardFunction · 0.90

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…