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 Static Toolbar #46

Merged
merged 1 commit into from
Feb 13, 2024
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
6 changes: 3 additions & 3 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Basic } from './Examples/Basic';
import { CustomKeyboardExample } from './Examples/CustomKeyboardExample';
import { EditorStickToKeyboardExample } from './Examples/EditorStickToKeyboardExample';
import { Advanced } from './Examples/Advanced/AdvancedRichText';
import { Compose } from './Examples/Compose/Compose';
import { CustomAndStaticToolbar } from './Examples/CustomAndStaticToolbar/CustomAndStaticToolbar';
import { WithKeyboard } from './Examples/WithKeyboard';
import { CustomCss } from './Examples/CustomCss';
import { ConfigureExtensions } from './Examples/ConfigureExtentions';
Expand Down Expand Up @@ -45,8 +45,8 @@ const examples = [
component: NavigationHeader,
},
{
name: 'Compose',
component: Compose,
name: 'CustomAndStaticToolbar',
component: CustomAndStaticToolbar,
},
{
name: 'Advanced',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ import {
TextInput,
Alert,
} from 'react-native';
import { useEditorBridge } from '@10play/tentap-editor';
import {
useEditorBridge,
useBridgeState,
type EditorBridge,
} from '@10play/tentap-editor';
import { Icon } from '../Icon';
import { ComposeRichText } from './ComposeRichText';
import { ComposeRichText } from './CustomRichText';

export const Compose = ({
export const CustomAndStaticToolbar = ({
navigation,
}: NativeStackScreenProps<any, any, any>) => {
const editor = useEditorBridge({
avoidIosKeyboard: true,
DEV: true,
initialContent: MAIL_INITIAL_CONTENT,
});

Expand Down Expand Up @@ -59,13 +62,37 @@ export const Compose = ({
style={[exampleStyles.textPrimary, exampleStyles.recipientField]}
placeholder="Subject"
/>
<StaticToolbar editor={editor} />
</View>
</View>
<ComposeRichText editor={editor} onSendClick={onSendClick} />
</SafeAreaView>
);
};

interface StaticToolbarProps {
editor: EditorBridge;
}
const StaticToolbar = ({ editor }: StaticToolbarProps) => {
const editorState = useBridgeState(editor);
return (
<View style={[exampleStyles.recipientField, exampleStyles.staticToolbar]}>
<TouchableOpacity onPress={editor.undo} disabled={!editorState.canUndo}>
<Icon
name={'undo'}
fill={editorState.canUndo ? 'black' : 'lightgray'}
/>
</TouchableOpacity>
<TouchableOpacity onPress={editor.redo} disabled={!editorState.canRedo}>
<Icon
name={'redo'}
fill={editorState.canRedo ? 'black' : 'lightgray'}
/>
</TouchableOpacity>
</View>
);
};

const exampleStyles = StyleSheet.create({
fullScreen: {
flex: 1,
Expand Down Expand Up @@ -100,6 +127,9 @@ const exampleStyles = StyleSheet.create({
fontSize: 14,
color: 'grey',
},
staticToolbar: {
justifyContent: 'flex-end',
},
});

const MAIL_INITIAL_CONTENT = `<p><br><br><br><br><a target="_blank" rel="noopener noreferrer nofollow" href="https://www.10play.dev">Sent With Tentap!</a></p>`;
4 changes: 4 additions & 0 deletions example/src/assets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ import send from './send.svg';
import formatting from './formatting.svg';
import bold from './bold.svg';
import h1 from './h1.svg';
import undo from './undo.svg';
import redo from './redo.svg';

export const icons = {
close,
send,
formatting,
bold,
h1,
undo,
redo,
};
4 changes: 4 additions & 0 deletions example/src/assets/redo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions example/src/assets/undo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading