This repository has been archived by the owner on Jun 15, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
360 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import styled from 'styled-components/native'; | ||
|
||
export const Container = styled.View` | ||
flex: 1; | ||
background-color: ${({ theme }) => theme.stylekitBackgroundColor}; | ||
`; | ||
|
||
export const Input = styled.TextInput.attrs(({ theme }) => ({ | ||
placeholderTextColor: theme.stylekitNeutralColor, | ||
}))` | ||
font-size: ${({ theme }) => theme.mainTextFontSize}px; | ||
padding: 0px; | ||
color: ${({ theme }) => theme.stylekitForegroundColor}; | ||
height: 100%; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import React, { useContext, useState, useRef, useMemo } from 'react'; | ||
import { TextInput, KeyboardType, Keyboard, Platform } from 'react-native'; | ||
import { ApplicationContext } from '@Root/ApplicationContext'; | ||
import { Container, Input } from './InputModal.styled'; | ||
import { TableSection } from '@Components/TableSection'; | ||
import { SectionedTableCell } from '@Components/SectionedTableCell'; | ||
import { ButtonCell } from '@Components/ButtonCell'; | ||
import { SCREEN_INPUT_MODAL_PASSCODE } from '@Root/screens2/screens'; | ||
import { ModalStackNavigationProp } from '@Root/App'; | ||
import { | ||
SectionedOptionsTableCell, | ||
Option, | ||
} from '@Components/SectionedOptionsTableCell'; | ||
|
||
type Props = ModalStackNavigationProp<typeof SCREEN_INPUT_MODAL_PASSCODE>; | ||
export const PasscodeInputModal = (props: Props) => { | ||
// Context | ||
const application = useContext(ApplicationContext); | ||
|
||
// State | ||
const [settingPassocode, setSettingPassocode] = useState(false); | ||
const [text, setText] = useState(''); | ||
const [confirmText, setConfirmText] = useState(''); | ||
const [keyboardType, setKeyboardType] = useState<KeyboardType>('default'); | ||
|
||
// Refs | ||
const textRef = useRef<TextInput>(null); | ||
const confirmTextRef = useRef<TextInput>(null); | ||
|
||
const onTextSubmit = () => { | ||
if (!confirmText) { | ||
confirmTextRef.current?.focus(); | ||
} else { | ||
// this.submit(); | ||
} | ||
}; | ||
|
||
const onSubmit = async () => { | ||
if (settingPassocode) { | ||
return; | ||
} | ||
setSettingPassocode(true); | ||
if (text !== confirmText) { | ||
application?.alertService?.alert( | ||
'The two values you entered do not match. Please try again.', | ||
'Invalid Confirmation', | ||
'OK' | ||
); | ||
setSettingPassocode(false); | ||
} else { | ||
await application?.setPasscode(text); | ||
setSettingPassocode(false); | ||
props.navigation.goBack(); | ||
} | ||
}; | ||
|
||
const keyboardOptions: Option[] = useMemo( | ||
() => [ | ||
{ | ||
title: 'General', | ||
key: 'default', | ||
selected: keyboardType === 'default', | ||
}, | ||
{ | ||
title: 'Numeric', | ||
key: 'numeric', | ||
selected: keyboardType === 'numeric', | ||
}, | ||
], | ||
[keyboardType] | ||
); | ||
|
||
const onKeyboardTypeSelect = (option: Option) => { | ||
setKeyboardType(option.key as KeyboardType); | ||
if (Platform.OS === 'ios') { | ||
// on Android, keyboard will update right away | ||
Keyboard.dismiss(); | ||
setTimeout(() => { | ||
textRef.current?.focus(); | ||
}, 100); | ||
} | ||
}; | ||
|
||
return ( | ||
<Container> | ||
<TableSection> | ||
<SectionedTableCell textInputCell first={true}> | ||
<Input | ||
ref={textRef} | ||
placeholder="Enter a passcode" | ||
onChangeText={setText} | ||
value={text} | ||
secureTextEntry | ||
autoCorrect={false} | ||
autoCapitalize={'none'} | ||
keyboardType={keyboardType} | ||
keyboardAppearance={application | ||
?.getThemeService() | ||
.keyboardColorForActiveTheme()} | ||
autoFocus={true} | ||
underlineColorAndroid={'transparent'} | ||
onSubmitEditing={onTextSubmit} | ||
/> | ||
</SectionedTableCell> | ||
|
||
<SectionedTableCell textInputCell first={false}> | ||
<Input | ||
ref={confirmTextRef} | ||
placeholder="Confirm passcode" | ||
onChangeText={setConfirmText} | ||
value={confirmText} | ||
secureTextEntry | ||
autoCorrect={false} | ||
autoCapitalize={'none'} | ||
keyboardType={keyboardType} | ||
keyboardAppearance={application | ||
?.getThemeService() | ||
.keyboardColorForActiveTheme()} | ||
underlineColorAndroid={'transparent'} | ||
onSubmitEditing={onSubmit} | ||
/> | ||
</SectionedTableCell> | ||
|
||
<SectionedOptionsTableCell | ||
title={'Keyboard Type'} | ||
options={keyboardOptions} | ||
onPress={onKeyboardTypeSelect} | ||
/> | ||
|
||
<ButtonCell | ||
maxHeight={45} | ||
disabled={settingPassocode || text.length === 0} | ||
title={'Save'} | ||
bold | ||
onPress={onSubmit} | ||
/> | ||
</TableSection> | ||
</Container> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React, { useContext, useState, useRef } from 'react'; | ||
import { TextInput } from 'react-native'; | ||
import { ApplicationContext } from '@Root/ApplicationContext'; | ||
import { Container, Input } from './InputModal.styled'; | ||
import { TableSection } from '@Components/TableSection'; | ||
import { SectionedTableCell } from '@Components/SectionedTableCell'; | ||
import { ButtonCell } from '@Components/ButtonCell'; | ||
import { SCREEN_INPUT_MODAL_TAG } from '@Root/screens2/screens'; | ||
import { ModalStackNavigationProp } from '@Root/App'; | ||
|
||
type Props = ModalStackNavigationProp<typeof SCREEN_INPUT_MODAL_TAG>; | ||
export const TagInputModal = (props: Props) => { | ||
// Context | ||
const application = useContext(ApplicationContext); | ||
|
||
// State | ||
const [text, setText] = useState(''); | ||
|
||
// Refs | ||
const textRef = useRef<TextInput>(null); | ||
|
||
const onSubmit = () => {}; | ||
|
||
return ( | ||
<Container> | ||
<TableSection> | ||
<SectionedTableCell textInputCell first={true}> | ||
<Input | ||
ref={textRef} | ||
placeholder={ | ||
props.route.params.initialValue ? 'Tag name' : 'New tag name' | ||
} | ||
onChangeText={setText} | ||
value={text} | ||
autoCorrect={false} | ||
autoCapitalize={'none'} | ||
keyboardAppearance={application | ||
?.getThemeService() | ||
.keyboardColorForActiveTheme()} | ||
autoFocus | ||
underlineColorAndroid={'transparent'} | ||
onSubmitEditing={onSubmit} | ||
/> | ||
</SectionedTableCell> | ||
|
||
<ButtonCell | ||
maxHeight={45} | ||
disabled={text.length === 0} | ||
title={'Save'} | ||
bold | ||
onPress={() => {}} | ||
/> | ||
</TableSection> | ||
</Container> | ||
); | ||
}; |
Oops, something went wrong.