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

[BUG]: application crashes when using the useEditorBridge hook #192

Open
ConstSkripl opened this issue Sep 2, 2024 · 5 comments
Open

[BUG]: application crashes when using the useEditorBridge hook #192

ConstSkripl opened this issue Sep 2, 2024 · 5 comments

Comments

@ConstSkripl
Copy link

ConstSkripl commented Sep 2, 2024

Describe the bug
A clear and concise description of what the bug is.
when I add to the code
const editor = useEditorBridge();
the application crashes and the following error appears
image
image

I'm using versions
"@10play/tentap-editor": "^0.5.19",
"react-native-webview": "^13.12.1",
"react": "18.2.0",
"react-native": "0.71.11",

@17Amir17
Copy link
Collaborator

17Amir17 commented Sep 3, 2024

Could you share your source code? Or share a repo where this is reproduced?

@ConstSkripl
Copy link
Author

when adding the line (const editor = useEditorBridge();) the application immediately crashes. I can add it in any part of the code, and this error is shown

import { RichText, Toolbar, useEditorBridge, BridgeExtension } from '@10play/tentap-editor';
import { useRoute } from '@react-navigation/native';
import { Platform } from 'react-native';
import { Edge } from 'react-native-safe-area-context';

import { isHeaderTransparent } from 'utils/isHeaderTransparent';
import { screensWithoutFooter } from 'utils/isTabBarVisible';

import { BASIC_SCROLL_HEIGHT, EXTRA_HEIGHT, EXTRA_SCROLL_HEIGHT, KEYBOARD_VERTICAL_OFFSET } from './constants';
import * as Styled from './styles';
import { SafeAreaViewContainerProps } from './types';

export const SafeAreaViewContainer: React.FC<SafeAreaViewContainerProps> = ({
  children,
  disableVerticalOffset,
  disableHorizontalOffset,
  isScrollable,
  contentContainerStyle,
  keyboardShouldPersistTaps,
  disableExtraHeight,
  paddingTop,
  paddingBottom,
  disableKeyboardOffset = false,
}) => {
  const route = useRoute();
  const editor = useEditorBridge();

  const getExtraScrollHeight = () => {
    // useBottomTabBarHeight() throws error when outside tab.navigator
    try {
      const isTabBarVisible = !screensWithoutFooter.includes(route.name);

      return isTabBarVisible ? EXTRA_SCROLL_HEIGHT : BASIC_SCROLL_HEIGHT;
    } catch {
      console.warn('There is no BottomTabBar on this screen');
    }
  };

  const getEdges = (): Edge[] => (isHeaderTransparent(route.name) ? ['left', 'top'] : ['left']);

  const extraScrollHeight = getExtraScrollHeight();

  return (
    // TODO - it's probably not even needed to use safearea here, it mostly
    // is handled by navigation headers or nav bottom tabs. but just to be on
    // the safe side it's left here with edges={['left']} - top, bottom or none at all
    // lead to ugly paddings on ios
    <Styled.SafeAreaViewStyled edges={getEdges()}>
      <Styled.Container
        disableVerticalOffset={disableVerticalOffset}
        disableHorizontalOffset={disableHorizontalOffset}
        paddingTop={paddingTop}
        paddingBottom={paddingBottom}
      >
        {isScrollable ? (
          <Styled.KeyboardAwareScrollView
            contentContainerStyle={contentContainerStyle}
            extraScrollHeight={!disableExtraHeight ? extraScrollHeight : 0}
            extraHeight={!disableExtraHeight ? EXTRA_HEIGHT : 0}
            keyboardShouldPersistTaps={keyboardShouldPersistTaps}
            enableResetScrollToCoords={false}
          >
            {children}
          </Styled.KeyboardAwareScrollView>
        ) : (
          <>
            {/* <RichText editor={editor} /> */}
            <Styled.KeyboardAvoidingView
              behavior="padding"
              keyboardVerticalOffset={disableKeyboardOffset ? 0 : KEYBOARD_VERTICAL_OFFSET}
              enabled={Platform.OS === 'ios'}
            >
              {/* <Toolbar editor={editor} /> */}
              {children}
            </Styled.KeyboardAvoidingView>
          </>
        )}
      </Styled.Container>
    </Styled.SafeAreaViewStyled>
  );
};

@17Amir17
Copy link
Collaborator

17Amir17 commented Sep 4, 2024

Are you using expo?

@ConstSkripl
Copy link
Author

Are you using expo?

no

@17Amir17
Copy link
Collaborator

I am unable to reproduce this. Could you provide a repo with the minimum amount of changes needed to reproduce?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants