Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions .github/workflows/iphone_duo_screenshots.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: iPhone Duo screenshots

on:
pull_request:
paths:
- lib/**
- ios/**
- pubspec.*
- submodules/**
- integration_test/iphone_duo_screenshots_test.dart
- test_driver/iphone_duo_screenshots.dart
- scripts/iphone_duo_capture.sh
- .github/workflows/iphone_duo_screenshots.yml

permissions:
contents: read

concurrency:
group: iphone-duo-screenshots-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
capture:
if: github.head_ref == 'feat/iphone-duo-layout'
runs-on: xcode-27
timeout-minutes: 40
env:
DUO_CAPTURE_DIR: ${{ github.workspace }}/build/iphone-duo-simulator
DUO_CAPTURE_PORT: '8765'
COCOAPODS_DISABLE_STATS: 'true'
steps:
- uses: actions/checkout@v7
with:
submodules: recursive
fetch-depth: 0
persist-credentials: false
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '27.1'
- name: Install Flutter dependencies
run: |
submodules/flutter/bin/flutter config --enable-swift-package-manager
submodules/flutter/bin/flutter pub get
- name: Install audited simulator pose tool
# Simulator-only private HID helper; never linked into the app.
# Audited version 0.3.1: no runtime network or credential access.
env:
HINGE_REVISION: 06cb720276281da7f1aadd3874acb0d0ae5eb2b5
run: |
echo "XDG_CACHE_HOME=$RUNNER_TEMP/duo-cache" >> "$GITHUB_ENV"
git clone https://github.com/artemnovichkov/hinge.git "$RUNNER_TEMP/hinge"
git -C "$RUNNER_TEMP/hinge" checkout --detach "$HINGE_REVISION"
echo "HINGE_BIN=$RUNNER_TEMP/hinge/bin/hinge" >> "$GITHUB_ENV"
mkdir -p "$DUO_CAPTURE_DIR"
git -C "$RUNNER_TEMP/hinge" rev-parse HEAD > "$DUO_CAPTURE_DIR/hinge-revision.txt"
- name: Boot the native iPhone Duo simulator
run: bash scripts/iphone_duo_capture.sh prepare
- name: Build unsigned simulator app
run: >-
submodules/flutter/bin/flutter build ios --simulator --debug --no-codesign
--no-pub --target integration_test/iphone_duo_screenshots_test.dart
--dart-define=DUO_CAPTURE_PORT=$DUO_CAPTURE_PORT
- name: Capture actual folded and unfolded displays
run: |
set -o pipefail
submodules/flutter/bin/flutter drive --no-pub \
--device-id "$HINGE_DEVICE" \
--use-application-binary=build/ios/iphonesimulator/Runner.app \
--driver test_driver/iphone_duo_screenshots.dart \
--target integration_test/iphone_duo_screenshots_test.dart \
--dart-define=DUO_CAPTURE_PORT="$DUO_CAPTURE_PORT" \
2>&1 | tee "$DUO_CAPTURE_DIR/flutter-drive.log"
- name: Collect native diagnostics
if: always()
run: bash scripts/iphone_duo_capture.sh diagnose
- uses: actions/upload-artifact@v6
if: always()
with:
name: iphone-duo-simulator
path: build/iphone-duo-simulator
if-no-files-found: warn
retention-days: 7
- name: Stop simulator
if: always() && env.HINGE_DEVICE != ''
run: xcrun simctl shutdown "$HINGE_DEVICE"
171 changes: 171 additions & 0 deletions integration_test/iphone_duo_screenshots_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
import 'dart:convert';
import 'dart:io';

import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:hacki/cubits/cubits.dart';
import 'package:hacki/main.dart' as app;
import 'package:hacki/screens/item/item_screen.dart';
import 'package:hacki/screens/widgets/widgets.dart';
import 'package:integration_test/integration_test.dart';
import 'package:material_ui/material_ui.dart';
import 'package:shared_preferences/shared_preferences.dart';

void main() {
final IntegrationTestWidgetsFlutterBinding binding =
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

testWidgets('Capture actual iPhone Duo display transitions', (
WidgetTester tester,
) async {
int nativeCaptures = 0;
binding.reportData = <String, dynamic>{'nativeCaptures': nativeCaptures};
// Native preferences only dismiss first-run UI. Content and window metrics
// come from the running app and the real simulator, without fixtures.
final SharedPreferences preferences = await SharedPreferences.getInstance();
await preferences.setBool('tour', true);
for (final Tips tip in Tips.values) {
await preferences.setBool('${tip.name}_tips_completed', true);
}
await app.main(testing: true);

Future<void> waitFor(bool Function() ready, String reason) async {
final DateTime deadline = DateTime.now().add(
const Duration(seconds: 120),
);
while (!ready() && DateTime.now().isBefore(deadline)) {
await tester.pump(const Duration(milliseconds: 250));
}
expect(ready(), isTrue, reason: reason);
await tester.pump(const Duration(seconds: 2));
// A resize updates SplitViewCubit after layout; paint its new state too.
await tester.pump();
await tester.pump();
}

Size windowSize() =>
tester.view.physicalSize / tester.view.devicePixelRatio;

Future<void> capture(String name, {String? nextPose}) async {
final HttpClient client = HttpClient()
..connectionTimeout = const Duration(seconds: 5);
try {
final DateTime deadline = DateTime.now().add(
const Duration(seconds: 30),
);
HttpClientRequest? request;
while (request == null) {
try {
request = await client.postUrl(
Uri.parse(
'http://127.0.0.1:${const int.fromEnvironment('DUO_CAPTURE_PORT', defaultValue: 8765)}/capture',
),
);
} on SocketException {
if (DateTime.now().isAfter(deadline)) rethrow;
await Future<void>.delayed(const Duration(milliseconds: 250));
}
}
request.headers.contentType = ContentType.json;
request.write(
jsonEncode(<String, Object?>{
'name': name,
'nextPose': nextPose,
'logicalWidth': windowSize().width,
'logicalHeight': windowSize().height,
'devicePixelRatio': tester.view.devicePixelRatio,
'physicalWidth': tester.view.physicalSize.width,
'physicalHeight': tester.view.physicalSize.height,
'viewPadding': <String, double>{
'left': tester.view.viewPadding.left,
'top': tester.view.viewPadding.top,
'right': tester.view.viewPadding.right,
'bottom': tester.view.viewPadding.bottom,
},
}),
);
final HttpClientResponse response = await request.close().timeout(
const Duration(seconds: 60),
);
final String body = await utf8.decoder.bind(response).join();
expect(response.statusCode, HttpStatus.ok, reason: body);
nativeCaptures++;
binding.reportData = <String, dynamic>{
...binding.reportData!,
'nativeCaptures': nativeCaptures,
'lastCapture': name,
};
} finally {
client.close(force: true);
}
}

final Finder stories = find.byType(StoryTile);
await waitFor(
() => stories.evaluate().isNotEmpty,
'Public HN stories should load',
);
final SplitViewCubit splitView = tester
.element(stories.first)
.read<SplitViewCubit>();
expect(windowSize().width, lessThan(SplitViewCubit.minimumSplitViewWidth));
expect(splitView.state.enabled, isFalse);
await capture('01-folded-feed', nextPose: 'open');

await waitFor(
() =>
windowSize().width >= SplitViewCubit.minimumSplitViewWidth &&
splitView.state.enabled,
'Opening the physical simulator should resize the actual app window',
);
final Finder storyWithComments = find.byWidgetPredicate(
(Widget widget) => widget is StoryTile && widget.story.descendants > 0,
);
expect(storyWithComments, findsWidgets);
await tester.tap(storyWithComments.first);
await waitFor(
() => find.byType(CommentTile).evaluate().isNotEmpty,
'The selected live HN thread should load comments',
);
final BuildContext detailContext = tester.element(find.byType(ItemScreen));
final CommentsCubit comments = detailContext.read<CommentsCubit>();
final int selectedStoryId = comments.state.item.id;
binding.reportData = <String, dynamic>{
...binding.reportData!,
'selectedStoryId': selectedStoryId,
};
final Size unfoldedSize = windowSize();
await capture('02-unfolded-thread', nextPose: 'rotate');

await waitFor(
() => windowSize() != unfoldedSize,
'Rotating the simulator should change actual window metrics',
);
expect(identical(detailContext.read<CommentsCubit>(), comments), isTrue);
await capture('03-unfolded-rotated-thread', nextPose: 'close');

await waitFor(
() =>
windowSize().width < SplitViewCubit.minimumSplitViewWidth &&
!splitView.state.enabled,
'Closing the simulator should return to the outer display',
);
expect(find.byTooltip('Back to stories'), findsOneWidget);
expect(comments.state.item.id, selectedStoryId);
expect(
identical(
tester.element(find.byType(ItemScreen)).read<CommentsCubit>(),
comments,
),
isTrue,
);
await capture('04-refolded-thread');
await tester.tap(find.byTooltip('Back to stories'));
await waitFor(
() => stories.evaluate().isNotEmpty,
'Returning from the selected thread should reveal the feed',
);
await capture('05-refolded-feed');
expect(nativeCaptures, 5);
}, timeout: const Timeout(Duration(minutes: 8)));
}
43 changes: 32 additions & 11 deletions lib/cubits/split_view/split_view_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,53 @@ part 'split_view_state.dart';
class SplitViewCubit extends HydratedCubit<SplitViewState> with Loggable {
SplitViewCubit({required PreferenceCubit preferenceCubit})
: _preferenceCubit = preferenceCubit,
_splitViewPreferred = preferenceCubit.state.isSplitViewEnabled,
super(const SplitViewState.init()) {
init();
}

static const double minimumSplitViewWidth = 600;

final PreferenceCubit _preferenceCubit;
bool _splitViewPreferred;
bool _hasWideWindow = false;
late final StreamSubscription<bool> _preferenceStateSubscription;

void init() {
_preferenceStateSubscription = _preferenceCubit.stream
.distinct(
(PreferenceState previous, PreferenceState current) =>
previous.isSplitViewEnabled == current.isSplitViewEnabled,
)
.map((PreferenceState prefState) => prefState.isSplitViewEnabled)
.listen((bool isSplitViewEnabled) {
isSplitViewEnabled ? enableSplitView() : disableSplitView();
.map((PreferenceState state) => state.isSplitViewEnabled)
.distinct()
.listen((bool preferred) {
_splitViewPreferred = preferred;
_updateEnabled();
});
}

void updateItemScreenArgs(ItemScreenArgs args) {
emit(state.copyWith(itemScreenArgs: args));
/// Re-evaluates the layout whenever the available window width changes.
void updateWindowWidth(double width) {
_hasWideWindow = width >= minimumSplitViewWidth;
_updateEnabled();
}

void enableSplitView() => emit(state.copyWith(enabled: true));
void _updateEnabled() {
final bool enabled = _hasWideWindow && _splitViewPreferred;
final bool revealSelectedStory =
state.enabled && !enabled && state.itemScreenArgs != null;
emit(
state.copyWith(
enabled: enabled,
showDetail: revealSelectedStory || state.showDetail,
),
);
}

void updateItemScreenArgs(ItemScreenArgs args) {
emit(state.copyWith(itemScreenArgs: args, showDetail: true));
}

void disableSplitView() => emit(state.copyWith(enabled: false));
/// Returns to the compact story list without discarding the selected thread.
void showStories() =>
emit(state.copyWith(showDetail: false, expanded: false));

void zoom() => emit(
state.copyWith(
Expand Down
10 changes: 9 additions & 1 deletion lib/cubits/split_view/split_view_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,37 @@ class SplitViewState extends Equatable {
required this.enabled,
required this.resizingAnimationDuration,
this.submissionPanelWidth,
this.showDetail = false,
});

const SplitViewState.init()
: enabled = false,
expanded = false,
submissionPanelWidth = null,
resizingAnimationDuration = Duration.zero,
itemScreenArgs = null;
itemScreenArgs = null,
showDetail = false;

final bool enabled;

/// Whether the selected thread is visible when only one pane fits.
final bool showDetail;
final bool expanded;
final double? submissionPanelWidth;
final Duration resizingAnimationDuration;
final ItemScreenArgs? itemScreenArgs;

SplitViewState copyWith({
bool? enabled,
bool? showDetail,
bool? expanded,
double? submissionPanelWidth,
Duration? resizingAnimationDuration,
ItemScreenArgs? itemScreenArgs,
}) {
return SplitViewState(
enabled: enabled ?? this.enabled,
showDetail: showDetail ?? this.showDetail,
expanded: expanded ?? this.expanded,
submissionPanelWidth: submissionPanelWidth ?? this.submissionPanelWidth,
resizingAnimationDuration:
Expand All @@ -42,6 +49,7 @@ class SplitViewState extends Equatable {
@override
List<Object?> get props => <Object?>[
enabled,
showDetail,
expanded,
submissionPanelWidth,
resizingAnimationDuration,
Expand Down
Loading
Loading