@momo-kits/arrangement-view 0.168.1-beta.18 → 0.168.1-beta.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/package.json +1 -1
- package/src/ArrangementView.android.tsx +4 -0
- package/src/SplitView.tsx +3 -1
- package/src/arrange.ts +10 -3
- package/src/types.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@momo-kits/arrangement-view",
|
|
3
|
-
"version": "0.168.1-beta.
|
|
3
|
+
"version": "0.168.1-beta.19",
|
|
4
4
|
"description": "Foldable-aware two-pane arrangement and hinge observation. Fork of react-native-arrangement-view 0.2.0 (MIT, Thiago Brezinski).",
|
|
5
5
|
"main": "./src/index.tsx",
|
|
6
6
|
"files": [
|
|
@@ -19,6 +19,8 @@ export function ArrangementView({
|
|
|
19
19
|
observeHinge = true,
|
|
20
20
|
hingePolicy,
|
|
21
21
|
hingeGap,
|
|
22
|
+
forceSplit,
|
|
23
|
+
primaryRatio,
|
|
22
24
|
...props
|
|
23
25
|
}: ArrangementViewProps) {
|
|
24
26
|
const [store, onHingeChange] = useHingeStore(observeHinge);
|
|
@@ -41,6 +43,8 @@ export function ArrangementView({
|
|
|
41
43
|
hingePolicy,
|
|
42
44
|
hingeGap,
|
|
43
45
|
rtl: I18nManager.isRTL,
|
|
46
|
+
forceSplit,
|
|
47
|
+
primaryRatio,
|
|
44
48
|
});
|
|
45
49
|
const { primary, secondary, problems } = resolveSlots(children);
|
|
46
50
|
warnOnce(problems);
|
package/src/SplitView.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useEffect, useRef, useState, type ReactNode } from 'react';
|
|
2
2
|
import {
|
|
3
|
+
Platform,
|
|
3
4
|
StyleSheet,
|
|
4
5
|
UIManager,
|
|
5
6
|
useWindowDimensions,
|
|
@@ -27,7 +28,7 @@ export interface SplitViewProps extends ViewProps {
|
|
|
27
28
|
onSplitChange?: (isSplit: boolean) => void;
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
|
-
* Optional.
|
|
31
|
+
* Optional. Share of the width `primary` takes beside `secondary`, e.g. 0.35
|
|
31
32
|
* for a sidebar like Settings. Default: the system decides.
|
|
32
33
|
*/
|
|
33
34
|
primaryRatio?: number;
|
|
@@ -89,6 +90,7 @@ export function SplitView({
|
|
|
89
90
|
style={[styles.flex, style]}
|
|
90
91
|
// side by side only: a narrow window keeps primary alone instead of stacking
|
|
91
92
|
axes={'horizontal'}
|
|
93
|
+
forceSplit={Platform.OS === 'android'}
|
|
92
94
|
onLayout={(e: LayoutChangeEvent) => {
|
|
93
95
|
setContainerWidth(e.nativeEvent.layout.width);
|
|
94
96
|
onLayout?.(e);
|
package/src/arrange.ts
CHANGED
|
@@ -30,6 +30,8 @@ export interface ArrangeOptions {
|
|
|
30
30
|
hingePolicy?: HingePolicy;
|
|
31
31
|
hingeGap?: number;
|
|
32
32
|
rtl?: boolean;
|
|
33
|
+
forceSplit?: boolean;
|
|
34
|
+
primaryRatio?: number;
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
export interface Frame {
|
|
@@ -75,13 +77,16 @@ export function arrange(
|
|
|
75
77
|
hingePolicy = 'avoidSeparating',
|
|
76
78
|
hingeGap = 24,
|
|
77
79
|
rtl = false,
|
|
80
|
+
forceSplit = false,
|
|
81
|
+
primaryRatio = 0,
|
|
78
82
|
}: ArrangeOptions
|
|
79
83
|
): PaneFrames {
|
|
80
84
|
const full = { left: 0, top: 0, width, height };
|
|
81
85
|
const tabletop =
|
|
82
86
|
fold?.halfOpened === true && fold.orientation === 'horizontal';
|
|
83
87
|
const twoColumns =
|
|
84
|
-
|
|
88
|
+
forceSplit ||
|
|
89
|
+
(window.height >= COMPACT_HEIGHT && window.width >= EXPANDED_WIDTH);
|
|
85
90
|
const twoRows = tabletop || (!twoColumns && window.height >= EXPANDED_HEIGHT);
|
|
86
91
|
const allows = (axis: Axis) => axes === 'both' || axes === axis;
|
|
87
92
|
const fits = (axis: Axis) =>
|
|
@@ -146,6 +151,8 @@ export function arrange(
|
|
|
146
151
|
? 'vertical'
|
|
147
152
|
: null;
|
|
148
153
|
if (!axis) return { primary: full, secondary: null };
|
|
149
|
-
|
|
150
|
-
|
|
154
|
+
if (axis === 'vertical') return split(axis, height / 2, height / 2);
|
|
155
|
+
const ratio = primaryRatio > 0 && primaryRatio < 1 ? primaryRatio : 0.5;
|
|
156
|
+
const edge = width * (rtl ? 1 - ratio : ratio);
|
|
157
|
+
return split(axis, edge, edge);
|
|
151
158
|
}
|
package/src/types.ts
CHANGED
|
@@ -23,10 +23,10 @@ export interface ArrangementViewProps extends ViewProps {
|
|
|
23
23
|
axes?: ArrangementAxes;
|
|
24
24
|
/** Disable hinge observation without affecting adaptive layout. Default true. */
|
|
25
25
|
observeHinge?: boolean;
|
|
26
|
-
/**
|
|
26
|
+
/** Split side by side whatever the size classes. Default false. */
|
|
27
27
|
forceSplit?: boolean;
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
29
|
+
* Share of the width the primary pane takes when split side by side,
|
|
30
30
|
* e.g. 0.35 for a sidebar like Settings. Default: the system decides.
|
|
31
31
|
*/
|
|
32
32
|
primaryRatio?: number;
|