Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f290b8b

Browse files
feat: add a flag to suppress accessibility color warning
1 parent 5279202 commit f290b8b

4 files changed

Lines changed: 17 additions & 4 deletions

File tree

example/nativebase.config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import { INativebaseConfig } from 'native-base';
2+
13
export default {
24
dependencies: {
35
'linear-gradient': require('expo-linear-gradient').LinearGradient,
46
},
5-
};
7+
suppressAccessibilityWarning: true,
8+
} as INativebaseConfig;

src/core/NativeBaseContext.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export {
99

1010
export interface INativebaseConfig {
1111
theme?: ITheme;
12+
suppressAccessibilityWarning?: boolean;
1213
dependencies?: {
1314
'linear-gradient': any;
1415
};

src/core/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export {
77
useAccessibleColors,
88
} from './color-mode';
99

10+
export { INativebaseConfig } from './NativeBaseContext';
11+
1012
export type {
1113
StorageManager,
1214
ColorMode,

src/hooks/useContrastText.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Color from 'tinycolor2';
22
import { useToken } from './useToken';
33
import { useAccessibleColors } from '../core/color-mode/hooks';
4+
import { useNativeBaseConfig } from '../core/NativeBaseContext';
45

56
export function useContrastText(bg: string, color?: string) {
67
let [
@@ -17,6 +18,10 @@ export function useContrastText(bg: string, color?: string) {
1718
color ?? '',
1819
]);
1920

21+
let suppressAccessibilityWarning = useNativeBaseConfig(
22+
'NativeBaseConfigProvider'
23+
).config.suppressAccessibilityWarning;
24+
2025
let [accessibleColors] = useAccessibleColors();
2126

2227
if (typeof bg !== 'string') {
@@ -37,7 +42,8 @@ export function useContrastText(bg: string, color?: string) {
3742
trueBg,
3843
trueColor,
3944
bg,
40-
color
45+
color,
46+
suppressAccessibilityWarning
4147
);
4248

4349
return textColor;
@@ -62,7 +68,8 @@ function getAccessibleContrastColor(
6268
trueBg: string,
6369
trueColor: string,
6470
bg: string,
65-
color?: string
71+
color?: string,
72+
suppressAccessibilityWarning?: boolean
6673
) {
6774
if (typeof trueBg !== 'string') {
6875
trueBg = bg;
@@ -88,7 +95,7 @@ function getAccessibleContrastColor(
8895
trueBg,
8996
trueColor ? trueColor : trueContrastColor
9097
);
91-
if (contrast < 3) {
98+
if (contrast < 3 && !suppressAccessibilityWarning) {
9299
console.warn(
93100
[
94101
`NativeBase: The contrast ratio of ${contrast}:1 for ${

0 commit comments

Comments
 (0)