@@ -21,12 +21,16 @@ const globalStyles = StyleSheet.create({
21
21
* height, and as many will be fit on a row as possible
22
22
* without tiles being smaller than this; they may be
23
23
* larger to fill the container horizontally).
24
+ * @param aspectRatio When null, the height of each tile is fluid (and rows
25
+ * are aligned to the top). Otherwise, the desired
26
+ * aspect ratio of each tile (where 16/9 = 16:9).
24
27
* @returns The created React component.
25
28
*/
26
29
export const createTiledComponent = (
27
30
columnSpacing : number ,
28
31
rowSpacing : number ,
29
- minimumTileSize : number
32
+ minimumTileSize : number ,
33
+ aspectRatio : null | number
30
34
) : React . FunctionComponent < React . PropsWithChildren < Record < never , never > > > => {
31
35
const Tiled : React . FunctionComponent < React . PropsWithChildren < Record < never , never > > > = ( { children } ) => {
32
36
const [ sizing , setSizing ] = React . useState < null | {
@@ -75,10 +79,14 @@ export const createTiledComponent = (
75
79
style . paddingLeft = columnSpacing
76
80
}
77
81
78
- if ( transformedChildren . length < sizing . perRow || rowSpacing === 0 ) {
79
- style . height = sizing . size
82
+ if ( aspectRatio === null ) {
83
+ if ( transformedChildren . length >= sizing . perRow && rowSpacing !== 0 ) {
84
+ style . paddingTop = rowSpacing
85
+ }
86
+ } else if ( transformedChildren . length < sizing . perRow || rowSpacing === 0 ) {
87
+ style . height = sizing . size / aspectRatio
80
88
} else {
81
- style . height = sizing . size + rowSpacing
89
+ style . height = sizing . size / aspectRatio + rowSpacing
82
90
style . paddingTop = rowSpacing
83
91
}
84
92
0 commit comments