Skip to content
Merged
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
21 changes: 21 additions & 0 deletions bindings/csharp/src/CNativeAPI/generated/View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ public static partial class Interop
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool native_view_is_supported();

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool native_view_is_update_pending(ulong self);

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool native_view_is_updating();

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool native_view_is_visible(ulong self);
Expand All @@ -84,6 +92,10 @@ public static partial class Interop
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool native_view_remove_subview_at(ulong self, CULong index);

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool native_view_request_update(ulong self);

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool native_view_set_default_backend(int backend);
Expand Down Expand Up @@ -256,12 +268,21 @@ public static partial class Interop
[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
public static extern void native_view_add_subview(ulong self, ulong subview);

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
public static extern void native_view_begin_updates();

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
public static extern void native_view_blur(ulong self);

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
public static extern void native_view_cancel_update(ulong self);

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
public static extern void native_view_clear_subviews(ulong self);

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
public static extern void native_view_end_updates([MarshalAs(UnmanagedType.I1)] bool redraw);

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
public static extern void native_view_focus(ulong self);

Expand Down
38 changes: 38 additions & 0 deletions bindings/csharp/src/NativeAPI/View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public sealed record Blurred(uint ViewId) : ViewEvent;
public sealed record ButtonClicked(uint ViewId) : ViewEvent;
public sealed record TextFieldChanged(uint ViewId, string? Text) : ViewEvent;
public sealed record TextFieldSubmitted(uint ViewId) : ViewEvent;
public sealed record Updating(uint ViewId) : ViewEvent;

internal static ViewEvent? FromRaw(in native_view_event_t raw)
{
Expand All @@ -57,6 +58,7 @@ public sealed record TextFieldSubmitted(uint ViewId) : ViewEvent;
case 2: return new ButtonClicked(raw.view_id);
case 3: return new TextFieldChanged(raw.view_id, Marshal.PtrToStringUTF8(raw.data.text_field_changed.text));
case 4: return new TextFieldSubmitted(raw.view_id);
case 5: return new Updating(raw.view_id);
default: return null;
}
}
Expand Down Expand Up @@ -129,6 +131,42 @@ public static ViewBackend GetDefaultBackend()
return (ViewBackend)rawResult;
}

public static void BeginUpdates()
{
Interop.native_view_begin_updates();
}

public static void EndUpdates(bool redraw)
{
Interop.native_view_end_updates(redraw);
}

public static bool IsUpdating()
{
var rawResult = Interop.native_view_is_updating();
return rawResult;
}

public bool RequestUpdate()
{
var rawResult = Interop.native_view_request_update(NativeHandle);
return rawResult;
}

public void CancelUpdate()
{
Interop.native_view_cancel_update(NativeHandle);
}

public bool IsUpdatePending
{
get
{
var rawResult = Interop.native_view_is_update_pending(NativeHandle);
return rawResult;
}
}

public uint Id
{
get
Expand Down
22 changes: 21 additions & 1 deletion bindings/dart/cnativeapi/lib/src/bindings_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2562,9 +2562,15 @@ external int native_view_add_listener_async(
@ffi.Native<ffi.Void Function(native_view_t$1, native_view_t$1)>()
external void native_view_add_subview(int view, int subview);

@ffi.Native<ffi.Void Function()>()
external void native_view_begin_updates();

@ffi.Native<ffi.Void Function(native_view_t$1)>()
external void native_view_blur(int view);

@ffi.Native<ffi.Void Function(native_view_t$1)>()
external void native_view_cancel_update(int view);

@ffi.Native<ffi.Void Function(native_view_t$1)>()
external void native_view_clear_subviews(int view);

Expand All @@ -2578,6 +2584,9 @@ external int native_view_create_with_native_view(
ffi.Pointer<ffi.Void> native_view,
);

@ffi.Native<ffi.Void Function(ffi.Bool)>()
external void native_view_end_updates(bool redraw);

@ffi.Native<ffi.Void Function(native_view_t$1)>()
external void native_view_focus(int view);

Expand Down Expand Up @@ -2695,6 +2704,12 @@ external bool native_view_is_focused(int view);
@ffi.Native<ffi.Bool Function()>()
external bool native_view_is_supported();

@ffi.Native<ffi.Bool Function(native_view_t$1)>()
external bool native_view_is_update_pending(int view);

@ffi.Native<ffi.Bool Function()>()
external bool native_view_is_updating();

@ffi.Native<ffi.Bool Function(native_view_t$1)>()
external bool native_view_is_visible(int view);

Expand All @@ -2716,6 +2731,9 @@ external bool native_view_remove_subview(int view, int subview);
@ffi.Native<ffi.Bool Function(native_view_t$1, ffi.UnsignedLong)>()
external bool native_view_remove_subview_at(int view, int index);

@ffi.Native<ffi.Bool Function(native_view_t$1)>()
external bool native_view_request_update(int view);

@ffi.Native<ffi.Void Function(native_view_t$1, ffi.UnsignedInt)>(
symbol: 'native_view_set_alignment',
)
Expand Down Expand Up @@ -5868,7 +5886,8 @@ enum native_view_event_type_t {
NATIVE_VIEW_EVENT_TYPE_BLURRED(1),
NATIVE_VIEW_EVENT_TYPE_BUTTON_CLICKED(2),
NATIVE_VIEW_EVENT_TYPE_TEXT_FIELD_CHANGED(3),
NATIVE_VIEW_EVENT_TYPE_TEXT_FIELD_SUBMITTED(4);
NATIVE_VIEW_EVENT_TYPE_TEXT_FIELD_SUBMITTED(4),
NATIVE_VIEW_EVENT_TYPE_UPDATING(5);

final int value;
const native_view_event_type_t(this.value);
Expand All @@ -5879,6 +5898,7 @@ enum native_view_event_type_t {
2 => NATIVE_VIEW_EVENT_TYPE_BUTTON_CLICKED,
3 => NATIVE_VIEW_EVENT_TYPE_TEXT_FIELD_CHANGED,
4 => NATIVE_VIEW_EVENT_TYPE_TEXT_FIELD_SUBMITTED,
5 => NATIVE_VIEW_EVENT_TYPE_UPDATING,
_ => throw ArgumentError(
'Unknown value for native_view_event_type_t: $value',
),
Expand Down
4 changes: 4 additions & 0 deletions bindings/dart/nativeapi/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## 0.6.0

- Add cancellable `View.requestUpdate()` notifications. Windows coalesces publication on the owning UI thread and drains pending native paint after each update.

- Add nested `View.beginUpdates()` / `View.endUpdates(redraw)` batches to coalesce layout. Windows also batches native moves and schedules geometry and visibility repaint after publication; self-rendering hosts can pass `false` to publish their own damage. Unchanged properties and absolute translations avoid redundant layout.

- **Breaking:** requires Flutter 3.50 / Dart 3.14. The experimental `runNativeApp()` in `package:nativeapi/standalone.dart` still depends on VM APIs that Dart 3.14 removed, so it cannot be compiled with this constraint until it is ported.
- macOS: preserve a pending Flutter quit decision when AppKit acknowledges synchronous cancellation, so approving the later Dart response exits normally ([nativeapi-core#65](https://github.com/libnativeapi/nativeapi-core/issues/65)).
- Linux: implement tray context menu popups and dismissal on X11, including double-click triggers. Document the native Wayland requirement to use host-rendered `Clicked` or `RightClicked` menus ([nativeapi-core#88](https://github.com/libnativeapi/nativeapi-core/issues/88)).
Expand Down
35 changes: 35 additions & 0 deletions bindings/dart/nativeapi/lib/src/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ sealed class ViewEvent {
.value) {
return TextFieldSubmittedEvent(viewId: raw.view_id);
}
if (raw.typeAsInt ==
c.native_view_event_type_t.NATIVE_VIEW_EVENT_TYPE_UPDATING.value) {
return ViewUpdatingEvent(viewId: raw.view_id);
}
return null;
}
}
Expand Down Expand Up @@ -179,6 +183,13 @@ final class TextFieldSubmittedEvent extends ViewEvent {
final ViewId viewId;
}

final class ViewUpdatingEvent extends ViewEvent {
const ViewUpdatingEvent({required this.viewId});

@override
final ViewId viewId;
}

class View implements ffi.Finalizable {
/// Adopts a handle returned by the C API and releases it when this
/// object becomes unreachable.
Expand Down Expand Up @@ -239,6 +250,30 @@ class View implements ffi.Finalizable {
return ViewBackend.fromValue(raw.value);
}

static void beginUpdates() {
c.native_view_begin_updates();
}

static void endUpdates(bool redraw) {
c.native_view_end_updates(redraw);
}

static bool isUpdating() {
return c.native_view_is_updating();
}

bool requestUpdate() {
return c.native_view_request_update(nativeHandle);
}

void cancelUpdate() {
c.native_view_cancel_update(nativeHandle);
}

bool get isUpdatePending {
return c.native_view_is_update_pending(nativeHandle);
}

ViewId get id {
return c.native_view_get_id(nativeHandle);
}
Expand Down
19 changes: 19 additions & 0 deletions bindings/dart/nativeapi/lib/src/web/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ final class TextFieldSubmittedEvent extends ViewEvent {
final ViewId viewId;
}

final class ViewUpdatingEvent extends ViewEvent {
const ViewUpdatingEvent({required this.viewId});

@override
final ViewId viewId;
}

class View {
View.fromHandle(this.nativeHandle);
View.borrowed(this.nativeHandle);
Expand All @@ -139,6 +146,18 @@ class View {

static ViewBackend getDefaultBackend() => unsupported();

static void beginUpdates() => unsupported();

static void endUpdates(bool redraw) => unsupported();

static bool isUpdating() => unsupported();

bool requestUpdate() => unsupported();

void cancelUpdate() => unsupported();

bool get isUpdatePending => unsupported();

ViewId get id => unsupported();

ViewBackend get backend => unsupported();
Expand Down
39 changes: 39 additions & 0 deletions bindings/go/nativeapi.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 26 additions & 1 deletion bindings/js/lib/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export type ViewEvent =
| { type: "blurred"; viewId: ViewId }
| { type: "buttonClicked"; viewId: ViewId }
| { type: "textFieldChanged"; viewId: ViewId; text: string | null }
| { type: "textFieldSubmitted"; viewId: ViewId };
| { type: "textFieldSubmitted"; viewId: ViewId }
| { type: "updating"; viewId: ViewId };

/** A native View, held through an owned handle. */
export class View extends NativeObject {
Expand Down Expand Up @@ -77,6 +78,30 @@ export class View extends NativeObject {
return native.native_view_get_default_backend();
}

static beginUpdates(): void {
native.native_view_begin_updates();
}

static endUpdates(redraw: boolean): void {
native.native_view_end_updates(redraw);
}

static isUpdating(): boolean {
return native.native_view_is_updating();
}

requestUpdate(): boolean {
return native.native_view_request_update(this.nativeHandle);
}

cancelUpdate(): void {
native.native_view_cancel_update(this.nativeHandle);
}

get isUpdatePending(): boolean {
return native.native_view_is_update_pending(this.nativeHandle);
}

get id(): ViewId {
return native.native_view_get_id(this.nativeHandle);
}
Expand Down
3 changes: 3 additions & 0 deletions bindings/js/src/generated/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,9 @@ inline Value ToValue(const native_view_event_t& event) {
case NATIVE_VIEW_EVENT_TYPE_TEXT_FIELD_SUBMITTED:
result.Set("type", Value::String("textFieldSubmitted"));
break;
case NATIVE_VIEW_EVENT_TYPE_UPDATING:
result.Set("type", Value::String("updating"));
break;
default:
return Value::Null();
}
Expand Down
Loading
Loading