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

chore: display error messages for PIN screens inline mode #1253

Merged
Merged
Show file tree
Hide file tree
Changes from 13 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
90 changes: 0 additions & 90 deletions packages/legacy/app/App.tsx

This file was deleted.

12 changes: 12 additions & 0 deletions packages/legacy/core/App/assets/img/error-filled.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions packages/legacy/core/App/assets/img/exclamation-mark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions packages/legacy/core/App/components/inputs/InlineErrorText.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from 'react'
import { View, StyleSheet, Text } from 'react-native'

import { useTheme } from '../../contexts/theme'
import { SvgProps } from 'react-native-svg'
import { InlineErrorConfig } from '../../container-api'

export enum InlineErrorType {
error,
warning,
}

export interface InlineMessageProps {
message: string
inlineType: InlineErrorType
config: InlineErrorConfig
}

const InlineErrorText: React.FC<InlineMessageProps> = ({ message, inlineType, config }) => {
const { InputInlineMessage } = useTheme()
const style = StyleSheet.create({
container: {
flexDirection: 'row',
alignContent: 'center',
marginVertical: 5,
paddingRight: 20,
},
icon: { marginRight: 4 },
})

const color =
inlineType === InlineErrorType.warning
? InputInlineMessage.inlineWarningText.color
: InputInlineMessage.inlineErrorText.color

const props: SvgProps = { height: 16, width: 16, color: color, style: style.icon }

return (
<View style={[style.container, config.style]}>
{inlineType === InlineErrorType.warning ? (
<InputInlineMessage.InlineWarningIcon {...props} />
) : (
<InputInlineMessage.InlineErrorIcon {...props} />
)}
<Text style={[InputInlineMessage.inlineErrorText]}>{message}</Text>
</View>
)
}

export default InlineErrorText
108 changes: 64 additions & 44 deletions packages/legacy/core/App/components/inputs/PINInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ import Icon from 'react-native-vector-icons/MaterialIcons'
import { hitSlop, minPINLength } from '../../constants'
import { useTheme } from '../../contexts/theme'
import { testIdWithKey } from '../../utils/testable'
import InlineErrorText, { InlineMessageProps } from './InlineErrorText'
import { InlineErrorPosition } from '../../container-api'

interface PINInputProps {
label?: string
onPINChanged?: (PIN: string) => void
testID?: string
accessibilityLabel?: string
autoFocus?: boolean
inlineMessage?: InlineMessageProps
}

const PINInputComponent = (
{ label, onPINChanged, testID, accessibilityLabel, autoFocus = false }: PINInputProps,
{ label, onPINChanged, testID, accessibilityLabel, autoFocus = false, inlineMessage }: PINInputProps,
ref: Ref<TextInput>
) => {
// const accessible = accessibilityLabel && accessibilityLabel !== '' ? true : false
Expand Down Expand Up @@ -58,53 +61,70 @@ const PINInputComponent = (
paddingHorizontal: 10,
},
})
const content = () => (
<View style={PINInputTheme.labelAndFieldContainer}>
<View style={style.codeFieldContainer}>
<CodeField
{...props}
testID={testID}
accessibilityLabel={accessibilityLabel}
accessible
value={PIN}
rootStyle={PINInputTheme.codeFieldRoot}
onChangeText={onChangeText}
cellCount={minPINLength}
keyboardType="numeric"
textContentType="password"
renderCell={({ index, symbol, isFocused }) => {
let child: React.ReactNode | string = ''
if (symbol) {
child = showPIN ? symbol : '●' // Show or hide PIN
} else if (isFocused) {
child = <Cursor />
}
return (
<View key={index} style={style.cell} onLayout={getCellOnLayoutHandler(index)}>
<Text style={style.cellText} maxFontSizeMultiplier={1}>
{child}
</Text>
</View>
)
}}
autoFocus={autoFocus}
ref={ref}
/>
</View>
<TouchableOpacity
style={style.hideIcon}
accessibilityLabel={showPIN ? t('PINCreate.Hide') : t('PINCreate.Show')}
accessibilityRole={'button'}
testID={showPIN ? testIdWithKey('Hide') : testIdWithKey('Show')}
onPress={() => setShowPIN(!showPIN)}
hitSlop={hitSlop}
>
<Icon color={PINInputTheme.icon.color} name={showPIN ? 'visibility-off' : 'visibility'} size={30} />
</TouchableOpacity>
</View>
)

const inlineMessageView = ({message, inlineType, config}: InlineMessageProps) => (
<InlineErrorText message={message} inlineType={inlineType} config={config} />
)
const inlineMessagePlaceholder = (placment: InlineErrorPosition) => {
if (inlineMessage && inlineMessage.config.position === placment) {
return inlineMessageView(inlineMessage)
}
//This is a fallback in case no position provided
if (inlineMessage && placment === InlineErrorPosition.Above && !inlineMessage.config.position) {
return inlineMessageView(inlineMessage)
}
}
return (
<View style={style.container}>
{label && <Text style={[TextTheme.label, { marginBottom: 8 }]}>{label}</Text>}
<View style={PINInputTheme.labelAndFieldContainer}>
<View style={style.codeFieldContainer}>
<CodeField
{...props}
testID={testID}
accessibilityLabel={accessibilityLabel}
accessible
value={PIN}
rootStyle={PINInputTheme.codeFieldRoot}
onChangeText={onChangeText}
cellCount={minPINLength}
keyboardType="numeric"
textContentType="password"
renderCell={({ index, symbol, isFocused }) => {
let child: React.ReactNode | string = ''
if (symbol) {
child = showPIN ? symbol : '●' // Show or hide PIN
} else if (isFocused) {
child = <Cursor />
}
return (
<View key={index} style={style.cell} onLayout={getCellOnLayoutHandler(index)}>
<Text style={style.cellText} maxFontSizeMultiplier={1}>
{child}
</Text>
</View>
)
}}
autoFocus={autoFocus}
ref={ref}
/>
</View>
<TouchableOpacity
style={style.hideIcon}
accessibilityLabel={showPIN ? t('PINCreate.Hide') : t('PINCreate.Show')}
accessibilityRole={'button'}
testID={showPIN ? testIdWithKey('Hide') : testIdWithKey('Show')}
onPress={() => setShowPIN(!showPIN)}
hitSlop={hitSlop}
>
<Icon color={PINInputTheme.icon.color} name={showPIN ? 'visibility-off' : 'visibility'} size={30} />
</TouchableOpacity>
</View>
{inlineMessagePlaceholder(InlineErrorPosition.Above)}
{content()}
{inlineMessagePlaceholder(InlineErrorPosition.Below)}
</View>
)
}
Expand Down
14 changes: 14 additions & 0 deletions packages/legacy/core/App/container-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,24 @@ import { NotificationReturnType, NotificationsInputProps } from './hooks/notific
import { NotificationListItemProps } from './components/listItems/NotificationListItem'
import { PINCreateHeaderProps } from './components/misc/PINCreateHeader'
import { CredentialListFooterProps } from './types/credential-list-footer'
import { ViewStyle } from 'react-native'

export type FN_ONBOARDING_DONE = (
dispatch: React.Dispatch<ReducerAction<unknown>>,
navigation: StackNavigationProp<AuthenticateStackParams>
) => GenericFn

export enum InlineErrorPosition {
Above,
Below,
}

export type InlineErrorConfig = {
enabled: boolean
position?: InlineErrorPosition
style?: ViewStyle
}

MosCD3 marked this conversation as resolved.
Show resolved Hide resolved
type LoadStateFn = (dispatch: React.Dispatch<ReducerAction<unknown>>) => Promise<void>

type ProofRequestTemplateFn = (useDevTemplates: boolean) => Array<ProofRequestTemplate>
Expand Down Expand Up @@ -111,6 +123,7 @@ export const UTILITY_TOKENS = {

export const CONFIG_TOKENS = {
CONFIG: 'config',
INLINE_ERRORS: 'errors.inline',
} as const

export const TOKENS = {
Expand Down Expand Up @@ -177,6 +190,7 @@ export type TokenMapping = {
[TOKENS.COMPONENT_HOME_FOOTER]: React.FC
[TOKENS.COMPONENT_CRED_EMPTY_LIST]: React.FC
[TOKENS.COMPONENT_RECORD]: React.FC
[TOKENS.INLINE_ERRORS]: InlineErrorConfig
[TOKENS.CUSTOM_NAV_STACK_1]: React.FC
}

Expand Down
1 change: 1 addition & 0 deletions packages/legacy/core/App/container-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export class MainContainer implements Container {
this._container.registerInstance(TOKENS.COMPONENT_RECORD, Record)
this._container.registerInstance(TOKENS.CACHE_CRED_DEFS, [])
this._container.registerInstance(TOKENS.CACHE_SCHEMAS, [])
this._container.registerInstance(TOKENS.INLINE_ERRORS, { enabled: false })
this._container.registerInstance(
TOKENS.FN_ONBOARDING_DONE,
(dispatch: React.Dispatch<ReducerAction<unknown>>, navigation: StackNavigationProp<AuthenticateStackParams>) => {
Expand Down
3 changes: 3 additions & 0 deletions packages/legacy/core/App/index.ts
MosCD3 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ export type {
Migration as MigrationState,
Tours as ToursState,
} from './types/state'

export type { InlineMessageProps } from './components/inputs/InlineErrorText'

export type { CredentialListFooterProps }
export * from './container-api'
export { MainContainer } from './container-impl'
Expand Down
Loading
Loading