Skip to content

Commit

Permalink
💫 Impl: setVisibility Options Arg
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Aug 30, 2022
1 parent 99d3a18 commit a355a4c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/components/PopoverView/PopoverView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import type { OnPopoverDidHideEvent } from '../../types/PopoverViewEvents';
import * as Helpers from '../../functions/helpers';

import { IS_PLATFORM_IOS } from '../../constants/LibEnv';
import { ErrorUtilities } from 'react-native-ios-utilities';
import { ErrorUtilities, NativeError } from 'react-native-ios-utilities';
import { RNIPopoverErrorCodes } from 'src/constants/RNIPopoverErrorCodes';


export class PopoverView extends
Expand Down Expand Up @@ -75,7 +76,14 @@ export class PopoverView extends
// ------------------------

/** show or hide the popover */
setVisibility = async (visibility: boolean) => {
setVisibility = async (
visibility: boolean,
options: {
suppressVisibilityError: boolean
} = {
suppressVisibilityError: true
}
) => {
const { lazyPopover } = this.getProps();
if(!IS_PLATFORM_IOS) return;

Expand All @@ -95,8 +103,20 @@ export class PopoverView extends

} catch(error: unknown){
if(ErrorUtilities.isNativeError(error)){
console.warn(`Code: ${error.code} - Message: ${error.message}`);
throw error;
const nativeError = error as NativeError;

const isVisibilityError = (
nativeError.code === RNIPopoverErrorCodes.popoverAlreadyHidden ||
nativeError.code === RNIPopoverErrorCodes.popoverAlreadyVisible
);

if(isVisibilityError && options.suppressVisibilityError){
// no-op - don't show "popover already visible/hidden"-related errors

} else {
console.warn(`Code: ${error.code} - Message: ${error.message}`);
throw error;
};

} else if((error as any) instanceof Error){
throw error;
Expand Down
13 changes: 13 additions & 0 deletions src/constants/RNIPopoverErrorCodes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { RNIBaseErrorCodes, RNIBaseErrorCode } from "react-native-ios-utilities";
import type { RNIPopoverErrorCode } from "src/types/RNIPopoverError";


export const RNIPopoverErrorCodes: {
[key in RNIPopoverErrorCode]: key;
} = {
...RNIBaseErrorCodes as {
[key in RNIBaseErrorCode]: key
},
popoverAlreadyHidden: 'popoverAlreadyHidden',
popoverAlreadyVisible: 'popoverAlreadyVisible'
};

0 comments on commit a355a4c

Please sign in to comment.