@sudobility/components-rn 1.0.18 → 1.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +26 -0
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +26 -0
- package/dist/index.esm.js.map +1 -1
- package/dist/ui/AspectFitView/AspectFitView.d.ts +27 -0
- package/dist/ui/AspectFitView/AspectFitView.d.ts.map +1 -0
- package/dist/ui/AspectFitView/index.d.ts +2 -0
- package/dist/ui/AspectFitView/index.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/ui/AspectFitView/AspectFitView.tsx +74 -0
- package/src/ui/AspectFitView/index.ts +1 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export interface AspectFitViewProps {
|
|
3
|
+
/** Aspect ratio as width / height (e.g. 16/9) */
|
|
4
|
+
aspectRatio: number;
|
|
5
|
+
/** Content to render inside the aspect ratio container */
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
/** Additional className for the outer container */
|
|
8
|
+
className?: string;
|
|
9
|
+
/** Additional className for the inner aspect ratio box */
|
|
10
|
+
innerClassName?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* AspectFitView - A container that maintains a fixed aspect ratio using AspectFit behavior.
|
|
14
|
+
*
|
|
15
|
+
* The inner box scales to be as large as possible while fitting entirely within
|
|
16
|
+
* the parent, constrained by both width and height. Content that overflows
|
|
17
|
+
* the box is scrollable. The box is horizontally centered.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* <AspectFitView aspectRatio={16 / 9}>
|
|
22
|
+
* <MyContent />
|
|
23
|
+
* </AspectFitView>
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare const AspectFitView: React.FC<AspectFitViewProps>;
|
|
27
|
+
//# sourceMappingURL=AspectFitView.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AspectFitView.d.ts","sourceRoot":"","sources":["../../../src/ui/AspectFitView/AspectFitView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAK/B,MAAM,WAAW,kBAAkB;IACjC,iDAAiD;IACjD,WAAW,EAAE,MAAM,CAAC;IACpB,0DAA0D;IAC1D,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,mDAAmD;IACnD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0DAA0D;IAC1D,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CA2CtD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ui/AspectFitView/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAC"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { View, ScrollView } from 'react-native';
|
|
3
|
+
import type { LayoutChangeEvent } from 'react-native';
|
|
4
|
+
import { cn } from '../../lib/utils';
|
|
5
|
+
|
|
6
|
+
export interface AspectFitViewProps {
|
|
7
|
+
/** Aspect ratio as width / height (e.g. 16/9) */
|
|
8
|
+
aspectRatio: number;
|
|
9
|
+
/** Content to render inside the aspect ratio container */
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
/** Additional className for the outer container */
|
|
12
|
+
className?: string;
|
|
13
|
+
/** Additional className for the inner aspect ratio box */
|
|
14
|
+
innerClassName?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* AspectFitView - A container that maintains a fixed aspect ratio using AspectFit behavior.
|
|
19
|
+
*
|
|
20
|
+
* The inner box scales to be as large as possible while fitting entirely within
|
|
21
|
+
* the parent, constrained by both width and height. Content that overflows
|
|
22
|
+
* the box is scrollable. The box is horizontally centered.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```tsx
|
|
26
|
+
* <AspectFitView aspectRatio={16 / 9}>
|
|
27
|
+
* <MyContent />
|
|
28
|
+
* </AspectFitView>
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export const AspectFitView: React.FC<AspectFitViewProps> = ({
|
|
32
|
+
aspectRatio,
|
|
33
|
+
children,
|
|
34
|
+
className,
|
|
35
|
+
innerClassName,
|
|
36
|
+
}) => {
|
|
37
|
+
const [size, setSize] = React.useState<{
|
|
38
|
+
width: number;
|
|
39
|
+
height: number;
|
|
40
|
+
} | null>(null);
|
|
41
|
+
|
|
42
|
+
const onLayout = React.useCallback((event: LayoutChangeEvent) => {
|
|
43
|
+
const { width, height } = event.nativeEvent.layout;
|
|
44
|
+
setSize({ width, height });
|
|
45
|
+
}, []);
|
|
46
|
+
|
|
47
|
+
// Calculate AspectFit dimensions
|
|
48
|
+
let innerWidth = 0;
|
|
49
|
+
let innerHeight = 0;
|
|
50
|
+
if (size) {
|
|
51
|
+
const parentRatio = size.width / size.height;
|
|
52
|
+
if (aspectRatio > parentRatio) {
|
|
53
|
+
// Width-constrained
|
|
54
|
+
innerWidth = size.width;
|
|
55
|
+
innerHeight = size.width / aspectRatio;
|
|
56
|
+
} else {
|
|
57
|
+
// Height-constrained
|
|
58
|
+
innerHeight = size.height;
|
|
59
|
+
innerWidth = size.height * aspectRatio;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<View className={cn('flex-1', className)} onLayout={onLayout}>
|
|
65
|
+
{size && (
|
|
66
|
+
<View className={cn('items-center', innerClassName)}>
|
|
67
|
+
<ScrollView style={{ width: innerWidth, height: innerHeight }}>
|
|
68
|
+
{children}
|
|
69
|
+
</ScrollView>
|
|
70
|
+
</View>
|
|
71
|
+
)}
|
|
72
|
+
</View>
|
|
73
|
+
);
|
|
74
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AspectFitView, type AspectFitViewProps } from './AspectFitView';
|