Skip to content

Commit 30cc788

Browse files
feat(mobile): redesign the Add environment sheet (#17092)
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 73e097b commit 30cc788

11 files changed

Lines changed: 439 additions & 226 deletions
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import ExpoModulesCore
2+
import UIKit
3+
4+
/// One continuous blur with a rounded-rect hole, horizontally centered. A
5+
/// single masked effect view avoids the seams of tiling separate blurs.
6+
final class T3FrostedCutoutView: ExpoView {
7+
var cutoutTop: CGFloat = 0 { didSet { setNeedsLayout() } }
8+
var cutoutWidth: CGFloat = 0 { didSet { setNeedsLayout() } }
9+
var cutoutHeight: CGFloat = 0 { didSet { setNeedsLayout() } }
10+
var cutoutRadius: CGFloat = 0 { didSet { setNeedsLayout() } }
11+
/// Follows the app theme, which can differ from the system appearance.
12+
var appearance: String = "dark" {
13+
didSet {
14+
effectView.effect = UIBlurEffect(
15+
style: appearance == "light" ? .systemThinMaterialLight : .systemThinMaterialDark)
16+
}
17+
}
18+
19+
private let effectView = UIVisualEffectView(effect: UIBlurEffect(style: .systemThinMaterialDark))
20+
private let cutoutMaskView = UIView()
21+
private let maskLayer = CAShapeLayer()
22+
23+
required init(appContext: AppContext? = nil) {
24+
super.init(appContext: appContext)
25+
isUserInteractionEnabled = false
26+
maskLayer.fillRule = .evenOdd
27+
cutoutMaskView.layer.addSublayer(maskLayer)
28+
effectView.mask = cutoutMaskView
29+
addSubview(effectView)
30+
}
31+
32+
override func layoutSubviews() {
33+
super.layoutSubviews()
34+
effectView.frame = bounds
35+
cutoutMaskView.frame = bounds
36+
maskLayer.frame = bounds
37+
let path = UIBezierPath(rect: bounds)
38+
if cutoutWidth > 0, cutoutHeight > 0 {
39+
let hole = CGRect(
40+
x: (bounds.width - cutoutWidth) / 2,
41+
y: cutoutTop,
42+
width: cutoutWidth,
43+
height: cutoutHeight
44+
)
45+
path.append(UIBezierPath(roundedRect: hole, cornerRadius: cutoutRadius))
46+
}
47+
maskLayer.path = path.cgPath
48+
}
49+
}

‎apps/mobile/modules/t3-native-controls/ios/T3NativeControlsModule.swift‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ public final class T3NativeControlsModule: Module {
5454
}
5555
}
5656

57+
View(T3FrostedCutoutView.self) {
58+
ViewName("FrostedCutout")
59+
Prop("cutoutTop") { (view: T3FrostedCutoutView, value: Double) in view.cutoutTop = CGFloat(value) }
60+
Prop("cutoutWidth") { (view: T3FrostedCutoutView, value: Double) in view.cutoutWidth = CGFloat(value) }
61+
Prop("cutoutHeight") { (view: T3FrostedCutoutView, value: Double) in view.cutoutHeight = CGFloat(value) }
62+
Prop("cutoutRadius") { (view: T3FrostedCutoutView, value: Double) in view.cutoutRadius = CGFloat(value) }
63+
Prop("appearance") { (view: T3FrostedCutoutView, value: String) in view.appearance = value }
64+
}
65+
5766
View(T3ContextSheetSizeView.self) {
5867
ViewName("ContextSheetSize")
5968
Prop("contentHeight") { (view: T3ContextSheetSizeView, height: Double) in

‎apps/mobile/src/components/AndroidScreenHeader.tsx‎

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useState, type ReactNode } from "react";
2-
import { View } from "react-native";
2+
import { ActivityIndicator, View } from "react-native";
33

44
import type { AppSymbolName } from "./AppSymbol";
55
import { AppText as Text } from "./AppText";
@@ -14,6 +14,7 @@ export interface AndroidHeaderAction {
1414
readonly icon: AppSymbolName;
1515
readonly onPress: () => void;
1616
readonly disabled?: boolean;
17+
readonly loading?: boolean;
1718
readonly selected?: boolean;
1819
}
1920

@@ -84,16 +85,26 @@ export function AndroidScreenHeader(props: {
8485
) : null}
8586
</View>
8687

87-
{visibleActions.map((action) => (
88-
<AndroidHeaderIconButton
89-
key={action.accessibilityLabel}
90-
accessibilityLabel={action.accessibilityLabel}
91-
disabled={action.disabled}
92-
selected={action.selected}
93-
icon={action.icon}
94-
onPress={action.onPress}
95-
/>
96-
))}
88+
{visibleActions.map((action) =>
89+
action.loading ? (
90+
<View
91+
key={action.accessibilityLabel}
92+
accessibilityLabel={action.accessibilityLabel}
93+
className="size-12 items-center justify-center"
94+
>
95+
<ActivityIndicator colorClassName="accent-header-foreground" />
96+
</View>
97+
) : (
98+
<AndroidHeaderIconButton
99+
key={action.accessibilityLabel}
100+
accessibilityLabel={action.accessibilityLabel}
101+
disabled={action.disabled}
102+
selected={action.selected}
103+
icon={action.icon}
104+
onPress={action.onPress}
105+
/>
106+
),
107+
)}
97108
{overflowActions.length > 0 ? (
98109
<AndroidAnchoredMenu
99110
actions={overflowActions.map((action, index) => ({
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { requireNativeView } from "expo";
2+
import { StyleSheet, type ViewProps } from "react-native";
3+
4+
import type { FrostedCutoutProps } from "./FrostedCutout.types";
5+
6+
const NativeFrostedCutout = requireNativeView<ViewProps & FrostedCutoutProps>(
7+
"T3NativeControls",
8+
"FrostedCutout",
9+
);
10+
11+
/** Fills its parent with one native blur that leaves a rounded hole clear. */
12+
export function FrostedCutout(props: FrostedCutoutProps) {
13+
return <NativeFrostedCutout {...props} pointerEvents="none" style={StyleSheet.absoluteFill} />;
14+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { useState } from "react";
2+
import { StyleSheet, View } from "react-native";
3+
import Svg, { Path } from "react-native-svg";
4+
5+
import type { FrostedCutoutProps } from "./FrostedCutout.types";
6+
7+
/** Fills its parent with a theme-matched tint that leaves a rounded hole clear. iOS blurs instead. */
8+
export function FrostedCutout(props: FrostedCutoutProps) {
9+
const [width, setWidth] = useState(0);
10+
const [height, setHeight] = useState(0);
11+
const x = (width - props.cutoutWidth) / 2;
12+
const y = props.cutoutTop;
13+
const w = props.cutoutWidth;
14+
const h = props.cutoutHeight;
15+
const r = Math.min(props.cutoutRadius, w / 2, h / 2);
16+
const hole = `M${x + r},${y} H${x + w - r} A${r},${r} 0 0 1 ${x + w},${y + r} V${y + h - r} A${r},${r} 0 0 1 ${x + w - r},${y + h} H${x + r} A${r},${r} 0 0 1 ${x},${y + h - r} V${y + r} A${r},${r} 0 0 1 ${x + r},${y} Z`;
17+
18+
return (
19+
<View
20+
pointerEvents="none"
21+
style={StyleSheet.absoluteFill}
22+
onLayout={(event) => {
23+
setWidth(event.nativeEvent.layout.width);
24+
setHeight(event.nativeEvent.layout.height);
25+
}}
26+
>
27+
{width > 0 ? (
28+
<Svg height={height} width={width}>
29+
<Path
30+
d={`M0,0 H${width} V${height} H0 Z ${hole}`}
31+
fill={props.appearance === "light" ? "#ffffff" : "#000000"}
32+
fillOpacity={0.55}
33+
fillRule="evenodd"
34+
/>
35+
</Svg>
36+
) : null}
37+
</View>
38+
);
39+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export interface FrostedCutoutProps {
2+
/** Distance from the top edge to the clear hole; the hole is centered horizontally. */
3+
readonly cutoutTop: number;
4+
readonly cutoutWidth: number;
5+
readonly cutoutHeight: number;
6+
readonly cutoutRadius: number;
7+
readonly appearance: "light" | "dark";
8+
}

‎apps/mobile/src/components/ScreenHeader.tsx‎

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { HeaderBarButtonMailSearchToolbarItem } from "react-native-screens";
22
import { useId } from "react";
3+
import { ActivityIndicator, View } from "react-native";
34
import { createNativeHeaderMenu } from "./nativeHeaderMenu.ios";
45
import { ScreenHeaderButton } from "./ScreenHeaderButton";
56
import { NativeHeaderToolbar, NativeStackScreenOptions } from "../native/StackHeader";
@@ -139,14 +140,25 @@ export function ScreenHeader(props: ScreenHeaderProps) {
139140
props.trailing) &&
140141
props.options?.unstable_headerRightItems === undefined ? (
141142
<NativeHeaderToolbar placement="right">
142-
{props.actions?.map((action) => (
143-
<ScreenHeaderButton
144-
key={action.accessibilityLabel}
145-
{...action}
146-
icon={iosIcon(action.icon)}
147-
separateBackground
148-
/>
149-
))}
143+
{props.actions?.map(({ loading, ...action }) =>
144+
loading ? (
145+
<NativeHeaderToolbar.Custom key={action.accessibilityLabel}>
146+
<View
147+
accessibilityLabel={action.accessibilityLabel}
148+
className="size-9 items-center justify-center"
149+
>
150+
<ActivityIndicator color={action.tintColor} />
151+
</View>
152+
</NativeHeaderToolbar.Custom>
153+
) : (
154+
<ScreenHeaderButton
155+
key={action.accessibilityLabel}
156+
{...action}
157+
icon={iosIcon(action.icon)}
158+
separateBackground
159+
/>
160+
),
161+
)}
150162
{refresh && !compactSearch ? (
151163
<ScreenHeaderButton
152164
accessibilityLabel={search?.refreshAccessibilityLabel}

‎apps/mobile/src/components/ScreenHeader.types.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export interface ScreenHeaderAction {
88
readonly icon: AppSymbolName;
99
readonly onPress: () => void;
1010
readonly disabled?: boolean;
11+
/** Shows a spinner in place of the icon while the action's work is pending. */
12+
readonly loading?: boolean;
1113
readonly selected?: boolean;
1214
readonly tintColor?: ColorValue;
1315
}

‎apps/mobile/src/features/connection/ConnectionSheetButton.tsx‎

Lines changed: 0 additions & 111 deletions
This file was deleted.

0 commit comments

Comments
 (0)