import { PixelRatio } from "react-native";
import { isNil, identity } from "ramda";
import { toNumber } from "@applicaster/zapp-react-native-utils/numberUtils";
import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";

// HACK - to prevent text flickering
export const withAdjustedLineHeight = (styles) => {
  const fontScale = PixelRatio.getFontScale();
  const lineHeight = toNumber(styles.lineHeight);

  if (isNil(lineHeight)) {
    return styles;
  }

  return { ...styles, lineHeight: lineHeight * fontScale };
};

export const withScaledLineHeight = platformSelect({
  ios: withAdjustedLineHeight,
  default: identity,
});
