@myun/gimi-chat 0.9.3 → 0.9.5

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.
@@ -215,6 +215,11 @@ var MessageList = function MessageList(_ref) {
215
215
  useVirtualScroll = _useState4[0],
216
216
  setUseVirtualScroll = _useState4[1];
217
217
  var VIRTUAL_SCROLL_THRESHOLD = 1200;
218
+ var isSafari = useMemo(function () {
219
+ if (typeof navigator === 'undefined') return false;
220
+ var ua = navigator.userAgent;
221
+ return /Safari/i.test(ua) && !/Chrome|Chromium|Edg/i.test(ua);
222
+ }, []);
218
223
  useEffect(function () {
219
224
  if (containerRef.current && containerRef.current !== scrollParent) {
220
225
  setScrollParent(containerRef.current);
@@ -229,10 +234,13 @@ var MessageList = function MessageList(_ref) {
229
234
  });
230
235
  }, [chatList, hideUserMessage]);
231
236
  useEffect(function () {
232
- if (!scrollParent) return;
237
+ if (!scrollParent || useVirtualScroll) return;
233
238
  var checkScrollHeight = function checkScrollHeight() {
234
239
  var shouldUseVirtual = scrollParent.scrollHeight > VIRTUAL_SCROLL_THRESHOLD && scrollParent.scrollHeight > scrollParent.clientHeight;
235
- setUseVirtualScroll(shouldUseVirtual);
240
+ console.log('shouldUseVirtual', shouldUseVirtual);
241
+ if (shouldUseVirtual) {
242
+ setUseVirtualScroll(true);
243
+ }
236
244
  };
237
245
  var resizeObserver = new ResizeObserver(function () {
238
246
  checkScrollHeight();
@@ -242,7 +250,7 @@ var MessageList = function MessageList(_ref) {
242
250
  return function () {
243
251
  resizeObserver.disconnect();
244
252
  };
245
- }, [scrollParent, visibleChatList.length]);
253
+ }, [scrollParent, visibleChatList.length, useVirtualScroll]);
246
254
  var renderItem = useCallback(function (_, v) {
247
255
  return /*#__PURE__*/React.createElement(MessageItem, {
248
256
  v: v,
@@ -281,7 +289,7 @@ var MessageList = function MessageList(_ref) {
281
289
  className: classNames(styles.container)
282
290
  }, visibleChatList.length > 0 && /*#__PURE__*/React.createElement("div", {
283
291
  className: styles.textWrap
284
- }, useVirtualScroll && scrollParent && platform === 'myun' ? /*#__PURE__*/React.createElement(Virtuoso, {
292
+ }, useVirtualScroll && scrollParent && platform === 'myun' && !isSafari ? /*#__PURE__*/React.createElement(Virtuoso, {
285
293
  style: {
286
294
  height: '100%',
287
295
  minHeight: 1
@@ -28,7 +28,8 @@ var useScroll = function useScroll(containerRef) {
28
28
  lastScrollTop: 0,
29
29
  isUserInteracting: false,
30
30
  wasAtBottom: true,
31
- lastWheelAt: 0
31
+ lastWheelAt: 0,
32
+ lastScrollAt: 0
32
33
  }).current;
33
34
  var scrollBottomNow = React.useCallback(function () {
34
35
  var tries = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 4;
@@ -123,9 +124,9 @@ var useScroll = function useScroll(containerRef) {
123
124
  var canScroll = scrollHeight - clientHeight > 1;
124
125
  if (!canScroll) return;
125
126
  var position = Math.max(0, scrollHeight - clientHeight - scrollTop);
126
- if (e.deltaY < -2) {
127
+ if (e.deltaY < 0) {
127
128
  markUserInteraction(true);
128
- } else if (e.deltaY > 2 && position <= bottomPosition) {
129
+ } else if (e.deltaY > 0 && position <= bottomPosition) {
129
130
  markUserInteraction(false);
130
131
  }
131
132
  }, 100), [containerRef.current, bottomPosition, markUserInteraction, refs]);
@@ -139,13 +140,11 @@ var useScroll = function useScroll(containerRef) {
139
140
  setCurrentPosition(position);
140
141
  setIsScrolling(true);
141
142
  refs.wasAtBottom = position <= bottomPosition * 2;
143
+ refs.lastScrollAt = Date.now();
142
144
  var scrollDelta = scrollTop - refs.lastScrollTop;
143
- if (Math.abs(scrollDelta) > 2) {
145
+ if (Math.abs(scrollDelta) > 0.5) {
144
146
  if (scrollDelta < 0) {
145
- var now = Date.now();
146
- if (refs.isUserInteracting || now - refs.lastWheelAt < 600) {
147
- markUserInteraction(true);
148
- }
147
+ markUserInteraction(true);
149
148
  } else if (scrollDelta > 0 && position <= bottomPosition) {
150
149
  markUserInteraction(false);
151
150
  }
@@ -194,6 +193,8 @@ var useScroll = function useScroll(containerRef) {
194
193
  }
195
194
  ;
196
195
  if (refs.isUserInteracting) return;
196
+ var now = Date.now();
197
+ if (now - refs.lastWheelAt < 200 || now - refs.lastScrollAt < 200) return;
197
198
  if (refs.wasAtBottom || distanceToBottom <= bottomPosition * 5) {
198
199
  scrollBottomNow(4);
199
200
  }