APSL / react-native-keyboard-aware-scroll-view

A ScrollView component that handles keyboard appearance and automatically scrolls to focused TextInput.
MIT License
5.24k stars 643 forks source link

Support for styled components #439

Open rostgoat opened 3 years ago

rostgoat commented 3 years ago

Styled components are great. Except I don't know how I can use them with custom RN components.

Example

Suppose I am using KeyboardAwareScrollView and I want to make it's styling reusable through styled components. SafeAreaView works fine but not KeyboardAwareScrollView

Currently I get an error when I do this:

const KeyboardAwareScrollView = styled.KeyboardAwareScrollView`
  flex: 1;
  justify-content: center;
  align-items: center;
`;

const SafeAreaView = styled.SafeAreaView`
  flex: 1;
  background-color: ${Colors.defaultWhite};
`;

const LoginScreen = ({ navigation }) => {
  const dispatch = useDispatch();

  return (
    <SafeAreaView keyboardShouldPersistTaps="handled">
      <KeyboardAwareScrollView
        extraHeight={200}>
        ...
      </KeyboardAwareScrollView>
    </SafeAreaView>
  );
};

I get this error

Error

Unhandled JS Exception: TypeError: _styledComponents.default.KeyboardAwareScrollView is not a function. (In '_styledComponents.default.KeyboardAwareScrollView(_templateObject())', '_styledComponents.default.KeyboardAwareScrollView' is undefined)

Anyone know a workaround?

rhuankarlus commented 3 years ago

Same problem here.

alexandreh92 commented 3 years ago

import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scrollview';

const MyAwareScrollView = styled(KeyboardAwareScrollView) /* your css */ ;