@momo-kits/foundation 0.169.12-beta.7 → 0.169.12-beta.8
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/Layout/screenHeader.tsx +56 -41
- package/package.json +1 -1
package/Layout/screenHeader.tsx
CHANGED
|
@@ -4,9 +4,9 @@ import { StackNavigationOptions } from '@react-navigation/stack';
|
|
|
4
4
|
import type { SharedValue } from 'react-native-reanimated';
|
|
5
5
|
import Navigation from '../Application/Navigation';
|
|
6
6
|
import { AnimatedHeader, SearchHeaderProps } from '../Application/types';
|
|
7
|
-
import { exportHeaderTitle } from '../Application/navigationOptions';
|
|
8
7
|
import { Colors, Spacing } from '../Consts';
|
|
9
8
|
import {
|
|
9
|
+
exportHeaderTitle,
|
|
10
10
|
HeaderBackground,
|
|
11
11
|
HeaderLeft,
|
|
12
12
|
HeaderTitle,
|
|
@@ -63,8 +63,9 @@ const getSearchTitleOptions = (
|
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
|
-
* Applies the Screen's navigation header (plain, extended, animated banner or search)
|
|
67
|
-
* re-applies it
|
|
66
|
+
* Applies the Screen's navigation header (plain, extended, animated banner or search), with
|
|
67
|
+
* a ref search header on top, and re-applies it on prop or layout change. Returns the
|
|
68
|
+
* search header setter and the tint.
|
|
68
69
|
*/
|
|
69
70
|
export const useScreenHeader = ({
|
|
70
71
|
navigation,
|
|
@@ -83,6 +84,7 @@ export const useScreenHeader = ({
|
|
|
83
84
|
}: ScreenHeaderParams) => {
|
|
84
85
|
const currentTint = useRef<string | undefined>(undefined);
|
|
85
86
|
const appliedHeaderMode = useRef<string | undefined>(undefined);
|
|
87
|
+
const searchHeaderParams = useRef<SearchHeaderProps | undefined>(undefined);
|
|
86
88
|
const headerLayout = useHeaderLayout(contentLayout);
|
|
87
89
|
const frameOptions = useHeaderFrameOptions(contentLayout);
|
|
88
90
|
|
|
@@ -243,45 +245,54 @@ export const useScreenHeader = ({
|
|
|
243
245
|
}, [navigation?.instance, sharedValue, frameOptions]);
|
|
244
246
|
|
|
245
247
|
// the search field spans the content (or the stretch frame), clear of the side bar
|
|
246
|
-
// and status bar clusters
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
258
|
-
const options: StackNavigationOptions = {
|
|
259
|
-
...frameOptions,
|
|
260
|
-
headerRight: undefined,
|
|
261
|
-
headerTitleContainerStyle: {
|
|
262
|
-
width: searchWidth,
|
|
263
|
-
maxWidth: searchWidth,
|
|
264
|
-
marginLeft: 0,
|
|
265
|
-
marginEnd: 0,
|
|
266
|
-
marginStart: 0,
|
|
267
|
-
marginHorizontal: 0,
|
|
268
|
-
marginVertical: 0,
|
|
269
|
-
margin: 0,
|
|
270
|
-
left: searchLeft,
|
|
271
|
-
},
|
|
272
|
-
headerLeft: (props: any) => {
|
|
273
|
-
if (params?.hiddenBack) {
|
|
274
|
-
return null;
|
|
275
|
-
}
|
|
276
|
-
return <HeaderLeft {...props} floating />;
|
|
277
|
-
},
|
|
278
|
-
headerTitle: () => (
|
|
279
|
-
<SearchHeader {...params} animatedValue={sharedValue} />
|
|
280
|
-
),
|
|
281
|
-
};
|
|
248
|
+
// and status bar clusters; kept as numbers so the setter below stays stable
|
|
249
|
+
let searchWidth = headerLayout.frameWidth;
|
|
250
|
+
let searchLeft = Spacing.M;
|
|
251
|
+
if (layout.sideBar) {
|
|
252
|
+
searchWidth = layout.contentWidth - Spacing.M * 2;
|
|
253
|
+
searchLeft = Spacing.M - getHeaderMargin(layout.width);
|
|
254
|
+
}
|
|
255
|
+
const clearance = layout.statusBarClearance;
|
|
256
|
+
if (clearance) {
|
|
257
|
+
searchWidth -= clearance.left + clearance.right;
|
|
258
|
+
}
|
|
282
259
|
|
|
283
|
-
|
|
284
|
-
|
|
260
|
+
/**
|
|
261
|
+
* Shows the search header and keeps its params: the header effect puts it back over the
|
|
262
|
+
* base header, so a call made before that effect, or a resize, does not lose it.
|
|
263
|
+
*/
|
|
264
|
+
const setSearchHeader = useCallback(
|
|
265
|
+
(params: SearchHeaderProps) => {
|
|
266
|
+
searchHeaderParams.current = params;
|
|
267
|
+
const options: StackNavigationOptions = {
|
|
268
|
+
...frameOptions,
|
|
269
|
+
headerRight: undefined,
|
|
270
|
+
headerTitleContainerStyle: {
|
|
271
|
+
width: searchWidth,
|
|
272
|
+
maxWidth: searchWidth,
|
|
273
|
+
marginLeft: 0,
|
|
274
|
+
marginEnd: 0,
|
|
275
|
+
marginStart: 0,
|
|
276
|
+
marginHorizontal: 0,
|
|
277
|
+
marginVertical: 0,
|
|
278
|
+
margin: 0,
|
|
279
|
+
left: searchLeft,
|
|
280
|
+
},
|
|
281
|
+
headerLeft: (props: any) => {
|
|
282
|
+
if (params?.hiddenBack) {
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
285
|
+
return <HeaderLeft {...props} floating />;
|
|
286
|
+
},
|
|
287
|
+
headerTitle: () => (
|
|
288
|
+
<SearchHeader {...params} animatedValue={sharedValue} />
|
|
289
|
+
),
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
navigation?.instance?.setOptions(options);
|
|
293
|
+
},
|
|
294
|
+
[navigation?.instance, sharedValue, frameOptions, searchWidth, searchLeft],
|
|
295
|
+
);
|
|
285
296
|
|
|
286
297
|
useEffect(() => {
|
|
287
298
|
const focus = navigation?.instance?.addListener?.('focus', () => {
|
|
@@ -302,6 +313,9 @@ export const useScreenHeader = ({
|
|
|
302
313
|
setHeaderType(headerType, appliedHeaderMode.current === headerType);
|
|
303
314
|
appliedHeaderMode.current = headerType;
|
|
304
315
|
}
|
|
316
|
+
if (searchHeaderParams.current) {
|
|
317
|
+
setSearchHeader(searchHeaderParams.current);
|
|
318
|
+
}
|
|
305
319
|
|
|
306
320
|
return () => {
|
|
307
321
|
focus?.();
|
|
@@ -315,6 +329,7 @@ export const useScreenHeader = ({
|
|
|
315
329
|
setAnimatedHeader,
|
|
316
330
|
setAnimatedSearch,
|
|
317
331
|
setHeaderType,
|
|
332
|
+
setSearchHeader,
|
|
318
333
|
]);
|
|
319
334
|
|
|
320
335
|
return { setSearchHeader, currentTint };
|