drawnui-react 0.1.0-preview.26 → 0.1.0-preview.27
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.
|
@@ -103,8 +103,19 @@ export declare class SkiaCarousel extends SnappingLayout {
|
|
|
103
103
|
protected FindNearestAnchorInternal(current: SKPoint, velocity: SKPoint): SKPoint;
|
|
104
104
|
/** C# SkiaCarousel.ScrollToNearestAnchor: velocity below SnapVelocityThreshold counts as none; looped snaps around virtual anchors. */
|
|
105
105
|
ScrollToNearestAnchor(location: SKPoint, velocity: SKPoint): void;
|
|
106
|
-
/** C# SkiaCarousel.SelectNextAnchor:
|
|
106
|
+
/** C# SkiaCarousel.SelectNextAnchor: the choice below, at most one slide from where a finger gesture started. */
|
|
107
107
|
SelectNextAnchor(origin: SKPoint, velocity: SKPoint): SKPoint;
|
|
108
|
+
/**
|
|
109
|
+
* A finger release moves at most one slide from the slide its gesture started on, as iOS paging and the Android
|
|
110
|
+
* ViewPager do (C# 1070e0db): a drag past the middle makes the next slide the nearest one, and the flick then went one
|
|
111
|
+
* further. Code moves (ScrollTo, SelectedIndex) are not limited: releaseHome is set only while a release snaps.
|
|
112
|
+
*/
|
|
113
|
+
private LimitToNeighbours;
|
|
114
|
+
/** The slide a finger gesture started on (the target when it caught a snap in flight), see LimitToNeighbours. */
|
|
115
|
+
private gestureHome?;
|
|
116
|
+
private releaseHome?;
|
|
117
|
+
/** Base choice, plus a wrap to the virtual anchor at the strip borders when looped. */
|
|
118
|
+
private SelectNextAnchorInternal;
|
|
108
119
|
/** C# FixIndex: a virtual anchor becomes the real one, the position keeps its offset (visually identical, looped drawing wraps). */
|
|
109
120
|
private FixIndex;
|
|
110
121
|
private FixPosition;
|
|
@@ -247,8 +247,30 @@ export class SkiaCarousel extends SnappingLayout {
|
|
|
247
247
|
}
|
|
248
248
|
super.ScrollToNearestAnchor(location, velocity);
|
|
249
249
|
}
|
|
250
|
-
/** C# SkiaCarousel.SelectNextAnchor:
|
|
250
|
+
/** C# SkiaCarousel.SelectNextAnchor: the choice below, at most one slide from where a finger gesture started. */
|
|
251
251
|
SelectNextAnchor(origin, velocity) {
|
|
252
|
+
return this.LimitToNeighbours(this.SelectNextAnchorInternal(origin, velocity));
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* A finger release moves at most one slide from the slide its gesture started on, as iOS paging and the Android
|
|
256
|
+
* ViewPager do (C# 1070e0db): a drag past the middle makes the next slide the nearest one, and the flick then went one
|
|
257
|
+
* further. Code moves (ScrollTo, SelectedIndex) are not limited: releaseHome is set only while a release snaps.
|
|
258
|
+
*/
|
|
259
|
+
LimitToNeighbours(target) {
|
|
260
|
+
const home = this.releaseHome;
|
|
261
|
+
if (!home)
|
|
262
|
+
return target;
|
|
263
|
+
const at = (p) => this.SnapPoints.findIndex((s) => Math.abs(s.X - p.X) <= 1 && Math.abs(s.Y - p.Y) <= 1);
|
|
264
|
+
const from = at(home), to = at(target);
|
|
265
|
+
if (from < 0 || to < 0 || Math.abs(to - from) <= 1)
|
|
266
|
+
return target; // a looped wrap goes to a virtual point next to the edge: one slide already
|
|
267
|
+
return this.SnapPoints[from + Math.sign(to - from)];
|
|
268
|
+
}
|
|
269
|
+
/** The slide a finger gesture started on (the target when it caught a snap in flight), see LimitToNeighbours. */
|
|
270
|
+
gestureHome;
|
|
271
|
+
releaseHome;
|
|
272
|
+
/** Base choice, plus a wrap to the virtual anchor at the strip borders when looped. */
|
|
273
|
+
SelectNextAnchorInternal(origin, velocity) {
|
|
252
274
|
if (!this.ApplyLoopedLogic)
|
|
253
275
|
return super.SelectNextAnchor(origin, velocity);
|
|
254
276
|
const baseTarget = super.SelectNextAnchor(origin, velocity);
|
|
@@ -551,6 +573,9 @@ export class SkiaCarousel extends SnappingLayout {
|
|
|
551
573
|
this.FixPosition();
|
|
552
574
|
this.panningOffset = this.CurrentPosition;
|
|
553
575
|
this.panningStart = this.CurrentPosition;
|
|
576
|
+
// a swipe that catches a snap in flight starts from the slide that snap was going to
|
|
577
|
+
const going = this.snapIfNoPanOnUp ? this.SnapPoints.find((s) => Math.abs(s.X - this.CurrentSnap.X) <= 1 && Math.abs(s.Y - this.CurrentSnap.Y) <= 1) : undefined;
|
|
578
|
+
this.gestureHome = going ?? (this.SnapPoints.length > 0 ? this.FindNearestAnchor(this.CurrentPosition) : undefined);
|
|
554
579
|
};
|
|
555
580
|
switch (args.Type) {
|
|
556
581
|
case "Down":
|
|
@@ -591,7 +616,13 @@ export class SkiaCarousel extends SnappingLayout {
|
|
|
591
616
|
consumed = this;
|
|
592
617
|
const final = this.velocityAccumulator.CalculateFinalVelocity(500);
|
|
593
618
|
this.CurrentSnap = this.CurrentPosition;
|
|
594
|
-
this.
|
|
619
|
+
this.releaseHome = this.gestureHome;
|
|
620
|
+
try {
|
|
621
|
+
this.ScrollToNearestAnchor(this.CurrentSnap, new SKPoint(final.X, final.Y));
|
|
622
|
+
}
|
|
623
|
+
finally {
|
|
624
|
+
this.releaseHome = undefined;
|
|
625
|
+
}
|
|
595
626
|
this.IsUserPanning = false;
|
|
596
627
|
this.IsUserFocused = false;
|
|
597
628
|
this.snapIfNoPanOnUp = false;
|
|
@@ -51,6 +51,8 @@ export declare class SkiaEditor extends SkiaShape {
|
|
|
51
51
|
CanShowCursor: boolean;
|
|
52
52
|
SelectionColor: Color;
|
|
53
53
|
private cursorPosition;
|
|
54
|
+
/** A caret position was given (by the app, a tap, a selection): focusing keeps it; otherwise focusing puts the caret at the end. */
|
|
55
|
+
private cursorPlaced;
|
|
54
56
|
private selectionLength;
|
|
55
57
|
private isFocused;
|
|
56
58
|
private controlStyle;
|
|
@@ -58,6 +58,8 @@ export class SkiaEditor extends SkiaShape {
|
|
|
58
58
|
CanShowCursor = true;
|
|
59
59
|
SelectionColor = "#5590CFFE";
|
|
60
60
|
cursorPosition = 0;
|
|
61
|
+
/** A caret position was given (by the app, a tap, a selection): focusing keeps it; otherwise focusing puts the caret at the end. */
|
|
62
|
+
cursorPlaced = false;
|
|
61
63
|
selectionLength = 0;
|
|
62
64
|
isFocused = false;
|
|
63
65
|
controlStyle = "Unset";
|
|
@@ -174,6 +176,7 @@ export class SkiaEditor extends SkiaShape {
|
|
|
174
176
|
/** Caret index (UTF-16 units) = the left edge of the selection when one exists. */
|
|
175
177
|
get CursorPosition() { return this.cursorPosition; }
|
|
176
178
|
set CursorPosition(v) {
|
|
179
|
+
this.cursorPlaced = true;
|
|
177
180
|
const p = Math.max(0, Math.min(this.text.length, v | 0));
|
|
178
181
|
if (p === this.cursorPosition)
|
|
179
182
|
return;
|
|
@@ -218,6 +221,14 @@ export class SkiaEditor extends SkiaShape {
|
|
|
218
221
|
if (SkiaEditor.Focused && SkiaEditor.Focused !== this)
|
|
219
222
|
SkiaEditor.Focused.IsFocused = false;
|
|
220
223
|
SkiaEditor.Focused = this;
|
|
224
|
+
// focused with no caret placed (from code, by the keyboard): the caret goes to the end of the text, as a tap after
|
|
225
|
+
// the text does, and the native field takes that position when it attaches (C# 2285b422: typing appends)
|
|
226
|
+
if (!this.cursorPlaced) {
|
|
227
|
+
this.cursorPlaced = true;
|
|
228
|
+
this.cursorPosition = this.text.length;
|
|
229
|
+
this.selectionLength = 0;
|
|
230
|
+
this.ScrollToCaret();
|
|
231
|
+
}
|
|
221
232
|
this.SetFocusNative(true);
|
|
222
233
|
this.StartBlink();
|
|
223
234
|
}
|
|
@@ -484,6 +495,7 @@ export class SkiaEditor extends SkiaShape {
|
|
|
484
495
|
this.stubSelectionStop = -1;
|
|
485
496
|
this.selectionMovingEdge = -1;
|
|
486
497
|
}
|
|
498
|
+
this.cursorPlaced = true;
|
|
487
499
|
if (!this.isFocused)
|
|
488
500
|
this.IsFocused = true;
|
|
489
501
|
this.OnCursorMoved();
|
|
@@ -505,6 +517,7 @@ export class SkiaEditor extends SkiaShape {
|
|
|
505
517
|
this.SelectWord(this.HitTestIndex(p.X, p.Y));
|
|
506
518
|
this.dragSelecting = true;
|
|
507
519
|
this.selectionAnchor = this.cursorPosition;
|
|
520
|
+
this.cursorPlaced = true;
|
|
508
521
|
if (!this.isFocused)
|
|
509
522
|
this.IsFocused = true;
|
|
510
523
|
return this;
|
|
@@ -541,6 +554,7 @@ export class SkiaEditor extends SkiaShape {
|
|
|
541
554
|
}
|
|
542
555
|
SelectAll() { this.SetSelection(0, this.text.length); }
|
|
543
556
|
SetSelection(start, end) {
|
|
557
|
+
this.cursorPlaced = true;
|
|
544
558
|
const s = Math.max(0, Math.min(this.text.length, Math.min(start, end))), e = Math.max(0, Math.min(this.text.length, Math.max(start, end)));
|
|
545
559
|
this.cursorPosition = s;
|
|
546
560
|
this.selectionLength = e - s;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drawnui-react",
|
|
3
|
-
"version": "0.1.0-preview.
|
|
3
|
+
"version": "0.1.0-preview.27",
|
|
4
4
|
"description": "DrawnUi for React: the DrawnUi (.NET) drawn-UI engine in TypeScript on CanvasKit (Skia WASM). Same controls, same PascalCase API as DrawnUi.Net.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Nick Kovalsky (AppoMobi)",
|
|
@@ -83,6 +83,8 @@
|
|
|
83
83
|
"check:thickness": "node dev/check.mjs dev/check-thickness.ts",
|
|
84
84
|
"check:scroll-recycled": "node dev/check.mjs dev/check-scroll-recycled.ts",
|
|
85
85
|
"check:masonry-keys": "node dev/check.mjs dev/check-masonry-keys.ts",
|
|
86
|
+
"check:carousel-swipe": "node dev/check.mjs dev/check-carousel-swipe.ts",
|
|
87
|
+
"check:editor-focus": "node dev/check.mjs dev/check-editor-focus.ts",
|
|
86
88
|
"site:extras": "node dev/site-extras.mjs dist/demo",
|
|
87
89
|
"build:lib": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
|
|
88
90
|
"prepublishOnly": "npm run build:lib",
|