react-native-ios-utilities
Version:
Utilities for react-native + iOS
71 lines • 2.14 kB
JavaScript
import * as React from 'react';
import { StyleSheet } from 'react-native';
import { RNIDummyViewModule } from './RNIDummyViewModule';
import { RNIDummyNativeView } from './RNIDummyNativeView';
export class RNIDummyView extends React.PureComponent {
nativeRef;
reactTag;
constructor(props) {
super(props);
}
;
getProps() {
const { shouldCleanupOnComponentWillUnmount, ...viewProps } = this.props;
return {
shouldCleanupOnComponentWillUnmount: shouldCleanupOnComponentWillUnmount ?? false,
viewProps,
};
}
;
componentWillUnmount() {
this.notifyOnComponentWillUnmount(false);
}
;
getNativeRef = () => {
return this.nativeRef;
};
getNativeReactTag = () => {
// @ts-ignore
return this.nativeRef?.nativeTag ?? this.reactTag;
};
notifyOnComponentWillUnmount = async (isManuallyTriggered = true) => {
const reactTag = this.getNativeReactTag();
if (typeof reactTag !== 'number')
return;
await RNIDummyViewModule.notifyOnComponentWillUnmount(reactTag, isManuallyTriggered);
};
_handleOnNativeRef = (ref) => {
this.nativeRef = ref;
};
_handleOnLayout = (event) => {
this.props.onLayout?.(event);
// @ts-ignore
this.reactTag = event.nativeEvent.target;
};
render() {
const props = this.getProps();
const didSetReactTag = this.reactTag != null;
return React.createElement(RNIDummyNativeView, {
...props.viewProps,
style: [
props.viewProps.style,
styles.nativeView,
],
// @ts-ignore
ref: this._handleOnNativeRef,
onLayout: (didSetReactTag
? undefined
: this._handleOnLayout),
shouldCleanupOnComponentWillUnmount: props.shouldCleanupOnComponentWillUnmount,
});
}
;
}
;
const styles = StyleSheet.create({
nativeView: {
position: 'absolute',
opacity: 0.01,
},
});
//# sourceMappingURL=RNIDummyView.js.map