react-crud-mobile 1.0.647 → 1.0.650

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.
@@ -0,0 +1 @@
1
+ export declare function useIsVisible(ref: any): boolean;
@@ -670,6 +670,36 @@ var styles$6 = /*#__PURE__*/reactNative.StyleSheet.create({
670
670
  }
671
671
  });
672
672
 
673
+ function useIsVisible(ref) {
674
+ var _useState = React.useState(false),
675
+ isVisible = _useState[0],
676
+ setIsVisible = _useState[1];
677
+ React.useEffect(function () {
678
+ var checkVisibility = function checkVisibility() {
679
+ if (!ref.current) return;
680
+ if (reactNative.Platform.OS === 'web') {
681
+ var rect = ref.current.getBoundingClientRect == null ? void 0 : ref.current.getBoundingClientRect();
682
+ if (rect && typeof window !== 'undefined') {
683
+ var windowHeight = window.innerHeight;
684
+ var visible = rect.top < windowHeight && rect.bottom > 0;
685
+ setIsVisible(visible);
686
+ }
687
+ } else {
688
+ ref.current.measureInWindow == null || ref.current.measureInWindow(function (x, y, width, height) {
689
+ var windowHeight = reactNative.Dimensions.get('window').height;
690
+ var visible = y < windowHeight && y + height > 0;
691
+ setIsVisible(visible);
692
+ });
693
+ }
694
+ };
695
+ var interval = setInterval(checkVisibility, 300); // roda a cada 300ms
696
+ return function () {
697
+ return clearInterval(interval);
698
+ };
699
+ }, [ref]);
700
+ return isVisible;
701
+ }
702
+
673
703
  function UIListRow(props) {
674
704
  var _repeat$list;
675
705
  var scope = props.scope;
@@ -692,26 +722,8 @@ function UIListRow(props) {
692
722
  data: item
693
723
  }))),
694
724
  row = _useState[0];
695
- var main = reactCrudUtils.ViewUtils.getCrud();
696
725
  var targetRef = React.useRef(null);
697
- var _useState2 = React.useState(false),
698
- visivel = _useState2[0],
699
- setVisivel = _useState2[1];
700
- var onScroll = function onScroll() {
701
- if (!visivel) {
702
- var handle = reactNative.findNodeHandle(targetRef.current);
703
- if (handle) {
704
- reactNative.UIManager.measure(handle, function (x, y, width, height, pageX, pageY) {
705
- var windowHeight = reactNative.Dimensions.get('window').height;
706
- var topoVisivel = pageY >= 0 && pageY < windowHeight;
707
- var fundoVisivel = pageY + height > 0 && pageY + height < windowHeight;
708
- setVisivel(topoVisivel || fundoVisivel);
709
- });
710
- }
711
- }
712
- };
713
- row.onScroll = onScroll;
714
- main.scroll[row.getName()] = row;
726
+ var isVisible = useIsVisible(targetRef);
715
727
  var onClick = function onClick(item) {
716
728
  row.call('click', {
717
729
  value: item,
@@ -721,7 +733,7 @@ function UIListRow(props) {
721
733
  });
722
734
  };
723
735
  var Child = function Child() {
724
- if (!visivel) {
736
+ if (!isVisible) {
725
737
  return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {});
726
738
  }
727
739
  return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
@@ -733,9 +745,9 @@ function UIListRow(props) {
733
745
  });
734
746
  };
735
747
  var ListItem = function ListItem() {
736
- var _useState3 = React.useState(0),
737
- updateIndex = _useState3[0],
738
- setUpdateIndex = _useState3[1];
748
+ var _useState2 = React.useState(0),
749
+ updateIndex = _useState2[0],
750
+ setUpdateIndex = _useState2[1];
739
751
  var key = scope.key('item');
740
752
  var getRowStyle = function getRowStyle() {
741
753
  var css = row.getStyle('row', _extends({}, styles.row));
@@ -752,7 +764,6 @@ function UIListRow(props) {
752
764
  return /*#__PURE__*/jsxRuntime.jsx(reactNative.View, {
753
765
  style: getRowStyle(),
754
766
  ref: targetRef,
755
- onLayout: onScroll,
756
767
  children: /*#__PURE__*/jsxRuntime.jsx(Child, {})
757
768
  }, key);
758
769
  }
@@ -760,7 +771,6 @@ function UIListRow(props) {
760
771
  style: getRowStyle(),
761
772
  underlayColor: 'transparent',
762
773
  ref: targetRef,
763
- onLayout: onScroll,
764
774
  onPress: function onPress(e) {
765
775
  e.stopPropagation();
766
776
  onClick(item);