Exposure Detection
You can detect whether a specific element is visible in a scroll view or list.
Detecting visibility
SDK component: InView
InView The component detects when an element starts appearing on the screen or disappears. When the element begins to be visible even a little, onChanged the handler is called and as the first argument true is passed. Conversely, when the element disappears from the screen, false is passed. onChanged As the handler's second argument, the element's screen visibility ratio is passed. The visibility ratio value is 0from 1.0 between. For example 0.2if it is passed, it means the component is visible on the screen by 20%.
Signature
class InView<T = ViewProps> extends PureComponent<InViewProps<T>> {
static contextType: import('react').Context<IOContextValue>;
static defaultProps: Partial<InViewProps>;
context: undefined | IOContextValue;
mounted: boolean;
protected element: Element;
protected instance: undefined | ObserverInstance;
protected view: any;
constructor(props: InViewProps<T>);
componentDidMount(): void;
componentWillUnmount(): void;
protected handleChange: (inView: boolean, areaThreshold: number) => void;
protected handleRef: (ref: any) => void;
protected handleLayout: (event: LayoutChangeEvent) => void;
measure: (...args: any) => void;
measureInWindow: (...args: any) => void;
measureLayout: (...args: any) => void;
setNativeProps: (...args: any) => void;
focus: (...args: any) => void;
blur: (...args: any) => void;
render(): import('react/jsx-runtime').JSX.Element | null;
}Parameters
props · Required ·
ObjectThe props object passed to the component.
props.children · Required ·
React.ReactNodeThese are the child components rendered beneath the component.
prop.asReact.ComponentType ·
ViewSpecifies the component to render. The default is View the View component.
triggerOnceboolean ·
falseUse this option to call
the onChangecallback only once when the element becomes visible on screen for the first time.onLayout(event: LayoutChangeEvent) => void
A callback function called when the layout changes.
onChange(inView: boolean, areaThreshold: number) => void
A callback function called when an element appears on or disappears from the screen. The first argument is the visibility state, and the second argument is the visibility ratio.
Example
Detect list visibility
SDK component: IOFlatList
IOFlatListis a component with Intersection Observer functionality added to detect whether a specific element appears or disappears on screen while scrolling FlatList It is a component. Using this component, you can easily check and handle whether each item in the list appears on screen.
InViewWhen used with it, you can check the visibility state of each element. The component included as a child element InView component IOFlatListdetects whether an element is visible on screen through its observation feature and triggers events according to the visibility state.
Signature
Example
Detect scroll area visibility
SDK component: IOScrollView, ImpressionArea
IOScrollViewand ImpressionAreaBy using it, you can check whether an element is visible within a scroll view. When a specific element appears on screen by at least a certain ratio, onImpressionStart the callback is called.
ImpressionAreaof areaThreshold If you set the value, when the element is visible by at least the set ratio onImpressionStart the callback is called.
Handling when an element appears by 20% or more in a scroll view
The following code has a height of 100pxan element with IOScrollViewfrom 20%or more visibleonImpressionStartis an example where the callback is called.
The red line 100pxof 20% is a visual representation of the point.
Last updated
Was this helpful?