Skip to content

Add exception description for showInputMethodPicker method on iOS #3

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

Merged
merged 2 commits into from
Dec 22, 2023
Merged
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
19 changes: 8 additions & 11 deletions example/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from "react";
import { Button, Modal, StyleSheet, View } from "react-native";
import { SafeKeyboardDetector } from "@bam.tech/react-native-app-security";
import { useState } from "react";
import { Button, Modal, Platform, StyleSheet, View } from "react-native";

export default function App() {
const [isModalVisible, setIsModalVisible] = useState(false);
Expand All @@ -19,7 +19,12 @@ export default function App() {
<Button title="fetch - valid certificates" onPress={fetchValid} />
<Button title="fetch - invalid certificates" onPress={fetchInvalid} />
<Button title="Is current keyboard safe?" onPress={checkIsKeyboardSafe} />
<Button title="show keyboard picker" onPress={showInputMethodPicker} />
{Platform.OS === "android" ? (
<Button
title="show keyboard picker"
onPress={() => SafeKeyboardDetector.showInputMethodPicker()}
/>
) : null}
</View>
);
}
Expand Down Expand Up @@ -66,11 +71,3 @@ const checkIsKeyboardSafe = () => {
const isKeyboardSafe = SafeKeyboardDetector.isCurrentKeyboardSafe();
console.warn("is Keyboard safe", isKeyboardSafe);
};

const showInputMethodPicker = () => {
try {
SafeKeyboardDetector.showInputMethodPicker();
} catch (error) {
console.warn("showInputMethodPicker threw. Did you call it on iOS?", error);
}
};
11 changes: 7 additions & 4 deletions ios/RNASModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class RNASModule: Module {
// There's nothing here related to SSL pinning because we use TrustKit's "auto-setup" via the config in `Info.plist`

Function("showInputMethodPicker") {() in
throw RNASModuleError.methodNotImplemented
throw InputMethodPickerUnavailableException()
}

Function("isCurrentKeyboardSafe") {() in
Expand All @@ -15,6 +15,9 @@ public class RNASModule: Module {
}
}

enum RNASModuleError: Error {
case methodNotImplemented
}

internal class InputMethodPickerUnavailableException: Exception {
override var reason: String {
return "Method not implemented on iOS since third-party keyboards security issues are not relevant on iOS."
}
}