0.0.12 • Published 2 years ago

my-test-intersection-observer v0.0.12

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

hippy-vue-intersection-observer

hippy-vue-intersection-observer is a Hippy-Vue implementation of Intersection Observer.

It provides an easier way to detect view exposure in complex application.

Note: This component is inspired by and adapted from 'rn-intersection-observer'

Install

# Install using Yarn:
yarn add hippy-vue-intersection-observer

# or NPM:
npm install -S hippy-vue-intersection-observer

Usage

Target view

<hippy-vue-observer
  scope="YourOwnScope"
  :thresholds="[0.2, 0.5]"
  @on-change="onIntersectionChange"
>
{/* your own view */}
</hippy-vue-observer>


<script>

import { HippyVueObserver, HippyIntersectionEmitEvent } from "hippy-vue-intersection-observer";

// register hippy-vue-observer before use
Vue.use(HippyVueObserver);

// ...

export default {
  // ...
  methods: {
    onIntersectionChange(entry) {
      console.log(entry);
    },
  },
  
}

</script>

Trigger detection from Vue

methods: {
    onScroll(e) {
      HippyIntersectionEmitEvent("myScope");
    },
}

Trigger detection from Native

HippyMap hippyMap = new HippyMap();
hippyMap.pushString("scope", "YourOwnScope");
mEngineManager.getCurrentEngineContext()
    .getModuleManager()
    .getJavaScriptModule(EventDispatcher.class)
    .receiveNativeEvent("IntersectionObserverEvent", hippyMap);
// 可参考HippyEventObserverModule.m
[self sendEvent:@"IntersectionObserverEvent" params:@{ @"scope": @"YourOwnScope" }];
- (void)sendEvent:(NSString *)eventName params:(NSDictionary *)params {
    HippyAssertParam(eventName);
    [self.bridge.eventDispatcher dispatchEvent:@"EventDispatcher" 
                                    methodName:@"receiveNativeEvent" 
                                          args:@{@"eventName": eventName, @"extra": params ? : @{}}];
}

Props & Params

1) IntersectionObserver / hippy-vue-observer

PropsParams TypeDescription
scopestringScope of the target View, required in event trigger.
rootMargin{top: number, left: number, bottom: number, right: number}Distance from screen edge of detect area.
thresholdsnumber[]Intersection ratios which should trigger intersection callbacks.
throttlenumberThrottle time between each detection(ms).

2) Intersection Callback (on-change)

Different from IntersectionObserver, hippy-vue-observer provides single parameter.

ParamsParams TypeDescription
boundingClientRect{top: number, left: number, bottom: number, right: number}Position of target View's edge.
intersectionRationumberIntersection ratio of target View in detect area
intersectionRect{top: number, left: number, bottom: number, right: number}Position of intersection area's edge.
targetRefRef of target View
isIntersectingbooleanDetermine current intersection ratio is larger than any threshold.

License

ISC

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago