Skip to content

Commit 9ff6ade

Browse files
authored
Merge branch 'main' into fix/ssh-remote-github-account
2 parents 8a398e0 + 7bafc40 commit 9ff6ade

93 files changed

Lines changed: 6497 additions & 593 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
-770 KB
Binary file not shown.
771 KB
Binary file not shown.

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public final class T3NativeControlsModule: Module {
1010
private var filePresentation: T3NativeFilePresentation?
1111

1212
public func definition() -> ModuleDefinition {
13+
Events("videoPlaybackChange")
1314
Constants {
1415
if #available(iOS 26.0, *) {
1516
return [
@@ -247,10 +248,16 @@ public final class T3NativeControlsModule: Module {
247248
userInfo: [NSLocalizedDescriptionKey: "The video preview is no longer available."]
248249
)
249250
}
250-
let presentation = T3NativeVideoPresentation(identifier: identifier, url: url, title: title) { [weak self] error in
251-
self?.videoPresentation = nil
252-
if let error { promise.reject(error) } else { promise.resolve(nil) }
253-
}
251+
let presentation = T3NativeVideoPresentation(
252+
identifier: identifier, url: url, title: title,
253+
onPlaybackChange: { [weak self] isPlaying in
254+
self?.sendEvent("videoPlaybackChange", ["identifier": identifier, "isPlaying": isPlaying])
255+
},
256+
completion: { [weak self] error in
257+
self?.videoPresentation = nil
258+
if let error { promise.reject(error) } else { promise.resolve(nil) }
259+
}
260+
)
254261
videoPresentation = presentation
255262
presentation.present(from: presenter, sources: presentationSources, sourceIdentifier: sourceIdentifier)
256263
}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ final class T3NativeVideoPresentation: NSObject, AVPlayerViewControllerDelegate,
77
private let controller = AVPlayerViewController()
88
private let completion: (Error?) -> Void
99
private var itemObservation: NSKeyValueObservation?
10+
private var playbackObservation: NSKeyValueObservation?
1011
private var backgroundObserver: NSObjectProtocol?
1112
private var playbackError: Error?
1213
private var presented = false
@@ -27,7 +28,8 @@ final class T3NativeVideoPresentation: NSObject, AVPlayerViewControllerDelegate,
2728
private weak var fullScreenController: UIViewController?
2829
private var embedded = false
2930

30-
init(identifier: String, url: URL, title: String, completion: @escaping (Error?) -> Void) {
31+
init(identifier: String, url: URL, title: String,
32+
onPlaybackChange: @escaping (Bool) -> Void, completion: @escaping (Error?) -> Void) {
3133
self.identifier = identifier
3234
self.completion = completion
3335
super.init()
@@ -38,6 +40,12 @@ final class T3NativeVideoPresentation: NSObject, AVPlayerViewControllerDelegate,
3840
metadata.value = title as NSString
3941
item.externalMetadata = [metadata]
4042
controller.player = AVPlayer(playerItem: item)
43+
playbackObservation = controller.player?.observe(\.timeControlStatus, options: [.new]) { player, _ in
44+
// Waiting keeps the playback request alive through buffering and seeks.
45+
if player.timeControlStatus != .waitingToPlayAtSpecifiedRate {
46+
onPlaybackChange(player.timeControlStatus == .playing)
47+
}
48+
}
4149
controller.delegate = self
4250
controller.overrideUserInterfaceStyle = .dark
4351
controller.allowsPictureInPicturePlayback = false
@@ -148,6 +156,7 @@ final class T3NativeVideoPresentation: NSObject, AVPlayerViewControllerDelegate,
148156
controller.removeFromParent()
149157
}
150158
itemObservation = nil
159+
playbackObservation = nil
151160
controller.player = nil
152161
if let backgroundObserver { NotificationCenter.default.removeObserver(backgroundObserver) }
153162
backgroundObserver = nil

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

Lines changed: 49 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@ import ExpoModulesCore
22
import UIKit
33

44
/// Wraps a screen's header scroll view. Where a column pads its content away from the iPhone Duo's
5-
/// vertical bar, this widens the scroll view under the bar. UIKit draws
6-
/// the header's scroll-edge effect inside the scroll view, so the blur reaches the bar like in the
7-
/// system apps while the content stays in the safe area. Everything happens in UIKit layout, so
8-
/// folds move the blur and the content together.
5+
/// vertical bar, this widens the scroll view under the bar, like the system apps' lists. UIKit
6+
/// draws the header's scroll-edge effect inside the scroll view, so the blur reaches the bar while
7+
/// the content stays in the safe area. Everything happens in UIKit layout, so folds move the blur
8+
/// and the content together.
99
final class T3ScrollEdgeBleedView: ExpoView {
1010
// Fabric recycles scroll views, so everything changed here is put back before this view leaves
1111
// the window, which unmounting does before any recycling.
1212
private var scrollView: UIScrollView?
1313
private var container: UIView?
14-
private var bleed: CGFloat = 0
14+
/// React Native's content view, which every row lives in.
15+
private var content: UIView?
16+
private var bleed = UIEdgeInsets.zero
1517
/// Whether the scroll view currently carries this view's changes.
1618
private var applied = false
1719
/// React Native's clipping, saved while bleeding. React Native only rewrites it when the
@@ -55,55 +57,72 @@ final class T3ScrollEdgeBleedView: ExpoView {
5557
detach()
5658
scrollView = found
5759
container = parent
60+
// React Native adds one plain UIView to its scroll view and mounts every child into it.
61+
content = found.subviews.first { type(of: $0) == UIView.self }
5862
}
5963
bleed = verticalBarBleed()
64+
// Without the content view to shift back, bleeding left would move the rows under the bar.
65+
if content == nil { bleed.left = 0 }
6066
apply()
6167
}
6268

63-
/// How far the vertical bar's safe area reaches past this view's right edge, when this view sits
64-
/// flush against the padding its column added for it. Nothing else is bled into: not a sidebar
65-
/// column overlapping this one, not a notch, and not a bar on the left, where widening would
66-
/// move the content and need a horizontal offset React Native keeps rewriting.
67-
private func verticalBarBleed() -> CGFloat {
68-
guard verticalBarIsOnTheRight() else { return 0 }
69+
/// How far the vertical bar's safe area reaches past this view's edge, when this view sits flush
70+
/// against the padding its column added for it. Nothing else is bled into: not a sidebar column
71+
/// overlapping this one, and not a notch.
72+
private func verticalBarBleed() -> UIEdgeInsets {
73+
guard let side = verticalBarSide() else { return .zero }
6974
var ancestor = superview
7075
while let view = ancestor {
71-
let inset = view.safeAreaInsets.right
76+
let inset = side == .left ? view.safeAreaInsets.left : view.safeAreaInsets.right
7277
if inset > 0 {
7378
let frame = convert(bounds, to: view)
74-
return abs(view.bounds.maxX - inset - frame.maxX) < 0.5 ? inset : 0
79+
let flush = side == .left
80+
? abs(frame.minX - (view.bounds.minX + inset)) < 0.5
81+
: abs(view.bounds.maxX - inset - frame.maxX) < 0.5
82+
guard flush else { return .zero }
83+
return side == .left
84+
? UIEdgeInsets(top: 0, left: inset, bottom: 0, right: 0)
85+
: UIEdgeInsets(top: 0, left: 0, bottom: 0, right: inset)
7586
}
7687
ancestor = view.superview
7788
}
78-
return 0
89+
return .zero
7990
}
8091

81-
private func verticalBarIsOnTheRight() -> Bool {
92+
private enum Side { case left, right }
93+
94+
private func verticalBarSide() -> Side? {
8295
// The vertical-bar API ships in the iOS 27.1 SDK (UIKit 9127.0.85); see T3LayoutMetricsView.
8396
#if canImport(UIKit, _version: 9127.0.85)
8497
if #available(iOS 27.1, *) {
8598
let rtl = effectiveUserInterfaceLayoutDirection == .rightToLeft
8699
switch traitCollection.verticalBarEdge {
87-
case .leading: return rtl
88-
case .trailing: return !rtl
89-
default: return false
100+
case .leading: return rtl ? .right : .left
101+
case .trailing: return rtl ? .left : .right
102+
default: return nil
90103
}
91104
}
92105
#endif
93-
return false
106+
return nil
94107
}
95108

96-
/// Widening to the right leaves the content where React Native laid it out, so only the frame,
97-
/// the container's clipping and the scroll indicator change; contentInset and contentOffset are
98-
/// never touched. Nothing at all is written unless this view is bleeding or undoing its bleed.
109+
/// Widening to the left would move the rows with it. Instead of a horizontal content offset,
110+
/// which React Native rewrites on its own layout passes, the content view's bounds origin shifts
111+
/// them back: React Native only ever sets that view's frame, which leaves its bounds origin.
112+
/// Nothing at all is written unless this view is bleeding or undoing its bleed.
99113
private func apply() {
100114
guard let scrollView, let container else { return }
101-
guard bleed > 0 || applied else { return }
115+
let bleeding = bleed != .zero
116+
guard bleeding || applied else { return }
102117
// React Native sizes the scroll view's component view; the UIScrollView inside follows it by
103118
// autoresizing, so the widened frame survives React Native's own layout updates.
104-
let frame = container.bounds.inset(by: UIEdgeInsets(top: 0, left: 0, bottom: 0, right: -bleed))
119+
let frame = container.bounds.inset(
120+
by: UIEdgeInsets(top: 0, left: -bleed.left, bottom: 0, right: -bleed.right))
105121
if scrollView.frame != frame { scrollView.frame = frame }
106-
if bleed == 0 {
122+
if let content, content.bounds.origin.x != -bleed.left {
123+
content.bounds.origin.x = -bleed.left
124+
}
125+
if !bleeding {
107126
if let clipped = containerClipped {
108127
containerClipped = nil
109128
container.layer.masksToBounds = clipped
@@ -115,19 +134,20 @@ final class T3ScrollEdgeBleedView: ExpoView {
115134
container.layer.masksToBounds = false
116135
}
117136
var indicators = scrollView.verticalScrollIndicatorInsets
118-
if indicators.right != bleed {
119-
indicators.right = bleed
137+
if indicators.right != bleed.right {
138+
indicators.right = bleed.right
120139
scrollView.verticalScrollIndicatorInsets = indicators
121140
}
122-
applied = bleed > 0
141+
applied = bleeding
123142
}
124143

125144
private func detach() {
126145
guard scrollView != nil else { return }
127-
bleed = 0
146+
bleed = .zero
128147
apply()
129148
scrollView = nil
130149
container = nil
150+
content = nil
131151
}
132152

133153
/// The scroll view sits a fixed few levels down (marker, React Native's scroll view component);

‎apps/mobile/modules/t3-terminal/android/src/main/java/expo/modules/t3terminal/T3TerminalModule.kt‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ class T3TerminalModule : Module() {
1111
// logs so a stale native binary is distinguishable from a broken key pipeline.
1212
Constants(
1313
"hardwareKeyRevision" to 2,
14+
"outputRevision" to 1,
1415
)
1516

1617
View(T3TerminalView::class) {
18+
AsyncFunction("writeOutput") { view: T3TerminalView, data: String, reset: Boolean ->
19+
view.writeOutput(data, reset)
20+
}
21+
1722
Prop("terminalKey") { view: T3TerminalView, terminalKey: String ->
1823
view.terminalKey = terminalKey
1924
}

‎apps/mobile/modules/t3-terminal/android/src/main/java/expo/modules/t3terminal/T3TerminalView.kt‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class T3TerminalView(context: Context, appContext: AppContext) : ExpoView(contex
5555
}
5656
private var terminalHandle = 0L
5757
private var fedBuffer = ""
58+
private var streamedOutput: TerminalOutputBuffer? = null
5859
private var cols = 0
5960
private var rows = 0
6061
private var clearingInput = false
@@ -361,6 +362,7 @@ class T3TerminalView(context: Context, appContext: AppContext) : ExpoView(contex
361362
paletteColors,
362363
)
363364
fedBuffer = ""
365+
streamedOutput?.let { output -> feedOutput(output.data) }
364366
}
365367

366368
private fun recreateTerminal() {
@@ -380,7 +382,7 @@ class T3TerminalView(context: Context, appContext: AppContext) : ExpoView(contex
380382
}
381383

382384
private fun feedPendingBuffer() {
383-
if (terminalHandle == 0L || initialBuffer == fedBuffer) return
385+
if (streamedOutput != null || terminalHandle == 0L || initialBuffer == fedBuffer) return
384386
if (!initialBuffer.startsWith(fedBuffer)) {
385387
recreateTerminal()
386388
if (terminalHandle == 0L) return
@@ -399,6 +401,29 @@ class T3TerminalView(context: Context, appContext: AppContext) : ExpoView(contex
399401
renderSnapshot()
400402
}
401403

404+
fun writeOutput(data: String, reset: Boolean) {
405+
if (isCleanedUp) return
406+
val output = streamedOutput ?: TerminalOutputBuffer()
407+
val bytes = data.toByteArray(Charsets.UTF_8)
408+
output.write(bytes, reset)
409+
streamedOutput = output
410+
if (reset) {
411+
recreateTerminal()
412+
} else if (terminalHandle != 0L) {
413+
feedOutput(bytes)
414+
renderSnapshot()
415+
}
416+
}
417+
418+
private fun feedOutput(data: ByteArray) {
419+
if (terminalHandle == 0L || data.isEmpty()) return
420+
emitResponse(GhosttyBridge.nativeFeed(terminalHandle, data))
421+
if (terminalCanvas.hasActiveSelection()) {
422+
GhosttyBridge.nativeClearSelection(terminalHandle)
423+
terminalCanvas.resetSelectionState()
424+
}
425+
}
426+
402427
private fun renderSnapshot() {
403428
if (terminalHandle == 0L) return
404429
TerminalFrame.decode(
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package expo.modules.t3terminal
2+
3+
import java.util.ArrayDeque
4+
5+
private const val REPLAY_LIMIT = 512 * 1024
6+
private const val REPLAY_CHUNK_SIZE = 16 * 1024
7+
8+
// Keep only replay history for intentional terminal recreation.
9+
internal class TerminalOutputBuffer {
10+
private val chunks = ArrayDeque<ByteArray>()
11+
private var firstOffset = 0
12+
private var tailSize = 0
13+
private var size = 0
14+
15+
// Only terminal recreation needs contiguous history; appends reuse the retained chunks.
16+
val data: ByteArray
17+
get() {
18+
val result = ByteArray(size)
19+
var destination = 0
20+
var start = firstOffset
21+
for (chunk in chunks) {
22+
val end = if (chunk === chunks.last) tailSize else chunk.size
23+
chunk.copyInto(result, destination, start, end)
24+
destination += end - start
25+
start = 0
26+
}
27+
return result
28+
}
29+
30+
fun write(incoming: ByteArray, reset: Boolean) {
31+
if (reset || incoming.size >= REPLAY_LIMIT) clear()
32+
var start = maxOf(0, incoming.size - REPLAY_LIMIT)
33+
while (start < incoming.size && incoming[start].toInt() and 0xC0 == 0x80) start += 1
34+
while (start < incoming.size) {
35+
if (chunks.isEmpty() || tailSize == REPLAY_CHUNK_SIZE) {
36+
chunks.addLast(ByteArray(REPLAY_CHUNK_SIZE))
37+
tailSize = 0
38+
}
39+
val count = minOf(incoming.size - start, REPLAY_CHUNK_SIZE - tailSize)
40+
incoming.copyInto(chunks.last, tailSize, start, start + count)
41+
start += count
42+
tailSize += count
43+
size += count
44+
}
45+
discardPrefix(maxOf(0, size - REPLAY_LIMIT))
46+
while (size > 0 && chunks.first[firstOffset].toInt() and 0xC0 == 0x80) discardPrefix(1)
47+
}
48+
49+
private fun discardPrefix(count: Int) {
50+
var remaining = count
51+
while (remaining > 0) {
52+
val end = if (chunks.size == 1) tailSize else chunks.first.size
53+
val discarded = minOf(remaining, end - firstOffset)
54+
firstOffset += discarded
55+
remaining -= discarded
56+
size -= discarded
57+
if (firstOffset == end) {
58+
chunks.removeFirst()
59+
firstOffset = 0
60+
if (chunks.isEmpty()) tailSize = 0
61+
}
62+
}
63+
}
64+
65+
private fun clear() {
66+
chunks.clear()
67+
firstOffset = 0
68+
tailSize = 0
69+
size = 0
70+
}
71+
}

‎apps/mobile/modules/t3-terminal/ios/T3TerminalModule.swift‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ public class T3TerminalModule: Module {
88
// logs so a stale native binary is distinguishable from a broken key pipeline.
99
Constants([
1010
"hardwareKeyRevision": 3,
11+
"outputRevision": 1,
1112
])
1213

1314
View(T3TerminalView.self) {
15+
AsyncFunction("writeOutput") { (view: T3TerminalView, data: String, reset: Bool) in
16+
view.writeOutput(data, reset: reset)
17+
}
18+
1419
Prop("terminalKey") { (view: T3TerminalView, terminalKey: String) in
1520
view.terminalKey = terminalKey
1621
}

0 commit comments

Comments
 (0)