react-crud-mobile 1.0.648 → 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,27 +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
- console.log(visivel);
702
- if (!visivel) {
703
- var handle = reactNative.findNodeHandle(targetRef.current);
704
- if (handle) {
705
- reactNative.UIManager.measure(handle, function (x, y, width, height, pageX, pageY) {
706
- var windowHeight = reactNative.Dimensions.get('window').height;
707
- var topoVisivel = pageY >= 0 && pageY < windowHeight;
708
- var fundoVisivel = pageY + height > 0 && pageY + height < windowHeight;
709
- setVisivel(topoVisivel || fundoVisivel);
710
- });
711
- }
712
- }
713
- };
714
- row.onScroll = onScroll;
715
- main.scroll[row.getName()] = row;
726
+ var isVisible = useIsVisible(targetRef);
716
727
  var onClick = function onClick(item) {
717
728
  row.call('click', {
718
729
  value: item,
@@ -722,7 +733,7 @@ function UIListRow(props) {
722
733
  });
723
734
  };
724
735
  var Child = function Child() {
725
- if (!visivel) {
736
+ if (!isVisible) {
726
737
  return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {});
727
738
  }
728
739
  return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
@@ -734,9 +745,9 @@ function UIListRow(props) {
734
745
  });
735
746
  };
736
747
  var ListItem = function ListItem() {
737
- var _useState3 = React.useState(0),
738
- updateIndex = _useState3[0],
739
- setUpdateIndex = _useState3[1];
748
+ var _useState2 = React.useState(0),
749
+ updateIndex = _useState2[0],
750
+ setUpdateIndex = _useState2[1];
740
751
  var key = scope.key('item');
741
752
  var getRowStyle = function getRowStyle() {
742
753
  var css = row.getStyle('row', _extends({}, styles.row));
@@ -753,7 +764,6 @@ function UIListRow(props) {
753
764
  return /*#__PURE__*/jsxRuntime.jsx(reactNative.View, {
754
765
  style: getRowStyle(),
755
766
  ref: targetRef,
756
- onLayout: onScroll,
757
767
  children: /*#__PURE__*/jsxRuntime.jsx(Child, {})
758
768
  }, key);
759
769
  }
@@ -761,7 +771,6 @@ function UIListRow(props) {
761
771
  style: getRowStyle(),
762
772
  underlayColor: 'transparent',
763
773
  ref: targetRef,
764
- onLayout: onScroll,
765
774
  onPress: function onPress(e) {
766
775
  e.stopPropagation();
767
776
  onClick(item);