Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add native module for reading high contrast #2795

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions native/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.facebook.react.uimanager.ViewManager;
import tuerantuer.app.integreat.constants.NativeConstantsModule;
import tuerantuer.app.integreat.fetcher.FetcherModule;
import tuerantuer.app.integreat.fetcher.HighContrastModule;

import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -23,6 +24,7 @@ public List<NativeModule> createNativeModules(ReactApplicationContext reactConte
List<NativeModule> modules = new ArrayList<>();
modules.add(new FetcherModule(reactContext));
modules.add(new NativeConstantsModule(reactContext));
modules.add(new HighContrastModule(reactContext));
return modules;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package tuerantuer.app.integreat.fetcher;

import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import android.util.Log;
import android.content.Context;
import android.view.accessibility.AccessibilityManager;
import com.facebook.react.bridge.Promise;

import java.lang.reflect.Method;


public class HighContrastModule extends ReactContextBaseJavaModule {
public HighContrastModule(ReactApplicationContext context) {
super(context);
}

@Override
public String getName() {
return "HighContrastModule";
}

@ReactMethod
public void isHighContrastMode(final Promise promise) {
ReactApplicationContext reactContext = getReactApplicationContext();
AccessibilityManager accessibilityManager = (AccessibilityManager) reactContext.getSystemService(Context.ACCESSIBILITY_SERVICE);
Class<?> accessibilityManagerClass = accessibilityManager.getClass();

Method isHighTextContrastEnabledMethod = null;
try {
isHighTextContrastEnabledMethod = accessibilityManagerClass.getMethod("isHighTextContrastEnabled");
} catch (NoSuchMethodException e) {
e.printStackTrace();
promise.reject("Method not found");
}

if (isHighTextContrastEnabledMethod != null) {
boolean result = true;
try {
result = (boolean) isHighTextContrastEnabledMethod.invoke(accessibilityManager);
} catch (Exception e) {
e.printStackTrace();
promise.reject("Method call failed");
}
promise.resolve(result);
} else {
promise.reject("Method not found");
}
promise.resolve(1);
}

}
1 change: 1 addition & 0 deletions native/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import buildConfig from './constants/buildConfig'
import { userAgent } from './constants/endpoint'
import AppContextProvider from './contexts/AppContextProvider'
import useSendOfflineJpalSignals from './hooks/useSendOfflineJpalSignals'
import { isHighContrastModeEnabled } from './utils/HighContrastMode'
import { backgroundAppStatePushNotificationListener } from './utils/PushNotificationsManager'
import sendTrackingSignal from './utils/sendTrackingSignal'

Expand Down
7 changes: 7 additions & 0 deletions native/src/utils/HighContrastMode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { NativeModules } from 'react-native'

export const isHighContrastModeEnabled = async (): Promise<boolean> => {
const { HighContrastModule } = NativeModules

return HighContrastModule.isHighContrastMode()
}