daybrush / infinite-viewer

Infinite Viewer is Document Viewer Component with infinite scrolling.
https://daybrush.com/infinite-viewer/
MIT License
296 stars 33 forks source link

Infinite - Viewer ,when the form component is selected Will automatically scroll, centering the current component #31

Open taoqingfeng opened 2 years ago

taoqingfeng commented 2 years ago

component: infinite-viewer version: ^0.14.3 image Infinite - Viewer ,when the form component is selected Will automatically scroll, centering the current component

taoqingfeng commented 2 years ago

The version is : ngx-infinite-viewer ^0.14.3 What should I do to avoid this behavior???

daybrush commented 2 years ago

@taoqingfeng

What options are you using for ngx-infinite-viewer?

taoqingfeng commented 2 years ago

image infiniteDragStart(e) { console.log('infiniteDragStart'); const target = e.inputEvent.target; } infiniteDragEnd(e) { console.log('infiniteDragStart'); if (!e.isDrag) { this.selecto.clickTarget(e.inputEvent); } } infiniteAbortPinch(e) { console.log('infiniteAbortPinch'); this.selecto.triggerDragStart(e.inputEvent); } infiniteDrag(e) { console.log('infiniteDrag'); } // 画布滚轮变化,标尺跟着变动 infiniteScroll(e) { console.log('infiniteScroll'); this.horizontalGuides.scroll(e.scrollLeft); this.horizontalGuides.scrollGuides(e.scrollTop); this.verticalGuides.scroll(e.scrollTop); this.verticalGuides.scrollGuides(e.scrollLeft); } infinitePinch(e) { console.log('infinitePinch'); }

daybrush commented 2 years ago

@taoqingfeng

I think it can be handled in selecto. Code where the target of moveable is changed

It should check the input at dragStart time. If tagName is select or input, preventDefault must be called.

my code is below: (for vanilla)

Options

{
        selectByClick: true,
        selectFromInside: false,
}

Events

// selecto
onSelectEnd = e => {
   // change target
   this.targets = e.selected;

    if (e.isDragStart) {
            e.inputEvent.preventDefault();

            setTimeout(() => {
                moveable.dragStart(e.inputEvent);
            });
    }
}
daybrush commented 2 years ago

@taoqingfeng

if things are different

Can you provide me a demo?

taoqingfeng commented 2 years ago

image

taoqingfeng commented 2 years ago

Thank you very much !!! here is the demo. https://stackblitz.com/edit/angular-ivy-yjtzrx?file=src/app/app.component.html.

taoqingfeng commented 2 years ago

and another question. How do I reset the Infinite Viewer when the width and height of an internal box change dynamically? image as the picture , the box is 19200px,but the guides is the initial 1920px, and the Infinite Viewer Scroll rolling range is still going to be 0~1920。 so,how should i do to reset the Infinite Viewer. I try to the api resize。 but the NgxInfiniteViewerComponent has no property 'resize' image

daybrush commented 2 years ago

@taoqingfeng

Use stopPropagation to true in ngx-moveable

<ngx-moveable
      ...
     [stopPropagation]="true"
     />
daybrush commented 2 years ago

@taoqingfeng ngx-infinite-viewer@0.15.0 is released.

resize method is added And useResizeObserver prop is added.

Use either one.

taoqingfeng commented 2 years ago

image image

I upgraded the ngx-infinite-viewer version 015.0, try to use the useResizeObserver and resize method. but it's not resolve my question. The scroll bar is still in the 0-1920 range, not change the value to 0-19200.

taoqingfeng commented 2 years ago

ngx-moveable add the [stopPropagation]="true" props. but The problem remains

daybrush commented 2 years ago

@taoqingfeng

ngx-infinite-viewer's new version is released. Check it again.

ngx-moveable add the [stopPropagation]="true" props. but The problem remains

Sep-04-2022 03-49-41

On my screen it looks like this:

can i know your screen gif?

taoqingfeng commented 2 years ago

Here's a GIF of the first problem figure 1

daybrush commented 2 years ago

@taoqingfeng

Use selecto option preventClickEventOnDragStart to true

  <ngx-selecto
    #selecto
    dragContainer=".scena-viewer"
    [selectableTargets]="['.select']"
    [hitRate]="0"
    [selectByClick]="true"
    [selectFromInside]="false"
    [toggleContinueSelect]="['shift']"
    [preventDefault]="true"
    [preventClickEventOnDragStart]="true"
    [ratio]="0"
    (dragStart)="onDragStart($event)"
    (drag)="onSelecttoDrag($event)"
    (selectEnd)="onSelectEnd($event)"
  ></ngx-selecto>
taoqingfeng commented 2 years ago

Thank you, this problem is solved by using preventClickEventOnDragStartproperties.

taoqingfeng commented 2 years ago
<ngx-infinite-viewer
      #InfiniteViewer
      class="scena-viewer"
      [zoom]="eds.scale_val / 100"
      [rangeX]="[0, 0]"
      [rangeY]="[0, 0]"
      [threshold]="0"
      [useWheelPinch]="false"
      (scroll)="infiniteScroll($event)"
      (dragStart)="infiniteDragStart($event)"
      (dragEnd)="infiniteDragEnd($event)"
    >
      <div
        [style]="{
          width: viewport_Width + 'px',
          height: viewport_Hight + 'px'
        }"
        class="view-box"
        (drop)="handleDrop($event)"
        (dragover)="handleOver($event)"
      >
        <app-json-parse
          [previewJson]="json"
          [useType]="'preview'"
          *ngIf="json"
        ></app-json-parse>
        <ngx-moveable
          #moveable
          [draggable]="draggable"
          [resizable]="resizable"
          [target]="targets"
          [snappable]="true"
          [snapGap]="true"
          [snapThreshold]="5"
          [isDisplaySnapDigit]="true"
          [snapDigit]="0"
          [stopPropagation]="true"
          [snapDirections]="{
            top: true,
            right: true,
            bottom: true,
            left: true,
            center: true,
            middle: true
          }"
          [elementSnapDirections]="{
            top: true,
            right: true,
            bottom: true,
            left: true
          }"
          [verticalGuidelines]="verticalSnapGuides"
          [horizontalGuidelines]="horizontalSnapGuides"
          [elementGuidelines]="elementGuidelines"
          [origin]="false"
          (resizeStart)="onResizeStart($event)"
          (resize)="onResize($event)"
          (resizeEnd)="onResizeEnd($event)"
          (dragStart)="move_onDragStart($event)"
          (drag)="onDrag($event)"
          (dragEnd)="onDragEnd($event)"
        >
        </ngx-moveable>
      </div>
    </ngx-infinite-viewer>
    this.eds.screenSize_handler.subscribe((res) => {
      this.viewport_Width = res.width;
      this.viewport_Hight = res.height;

      this.horizontalGuides.resize();
      this.verticalGuides.resize();

      this.InfiniteViewer.resize();
    });

The NGx-infinite Viewer has a box inside it, and I dynamically control its width and height by viewport_Width and viewport_Hight. However, the scroll bar of NGX-Infinite Viewer does not change when I change viewport_Width or viewport_Hight. It must wait until the next time the viewport_Width value changes to update the last view.

Video_20220906092913 00_00_00-00_00_30

taoqingfeng commented 2 years ago

This is my other question.

daybrush commented 2 years ago

@taoqingfeng

Perhaps an update has been made in this regard. Try installing the new version.

taoqingfeng commented 2 years ago

I have upgraded NGX-Infinite-Viewer to version 0.15.2, but the problem still persists

daybrush commented 2 years ago

@taoqingfeng

0.15.3 is released. Check it agian.

taoqingfeng commented 2 years ago

Thank you very much. Problem solved