private _adaptStyles()

in src/native-common/Styles.ts [149:222]


    private _adaptStyles<S extends RX.Types.ViewAndImageCommonStyle>(def: S,
            cacheStyle: boolean, isTextStyle = false): Readonly<RX.Types.StyleRuleSet<S>> {
        let adaptedRuleSet = def as ReactNativeViewAndImageCommonStyle<S>;
        if (cacheStyle) {
            StyleLeakDetector.detectLeaks(def);

            // Forbidden props are not allowed in uncached styles. Perform the
            // omit only in the cached path.
            adaptedRuleSet = omit<S>(adaptedRuleSet, forbiddenProps) as ReactNativeViewAndImageCommonStyle<S>;
        }

        // Convert text styling
        const textStyle = adaptedRuleSet as RX.Types.TextStyle;
        if (textStyle.font) {
            if (textStyle.font.fontFamily !== undefined) {
                textStyle.fontFamily = textStyle.font.fontFamily;
            }
            if (textStyle.font.fontWeight !== undefined) {
                textStyle.fontWeight = textStyle.font.fontWeight;
            }
            if (textStyle.font.fontStyle !== undefined) {
                textStyle.fontStyle = textStyle.font.fontStyle;
            }
            delete textStyle.font;
        }

        if (isTextStyle) {
            if (textStyle.shadowColor !== undefined) {
                adaptedRuleSet.textShadowColor = textStyle.shadowColor;
                delete textStyle.shadowColor;
            }
            if (textStyle.shadowOffset !== undefined) {
                adaptedRuleSet.textShadowOffset = textStyle.shadowOffset;
                delete textStyle.shadowOffset;
            }
            if (textStyle.shadowRadius !== undefined) {
                adaptedRuleSet.textShadowRadius = textStyle.shadowRadius;
                delete textStyle.shadowRadius;
            }
        }

        if (def.flex !== undefined) {
            // In development mode, see if we're going to overwrite explicit flexGrow
            // or flexShrink attributes. It's a programming error to specify these in
            // combination with flex.
            if (AppConfig.isDevelopmentMode()) {
                if (adaptedRuleSet.flexGrow !== undefined || adaptedRuleSet.flexShrink !== undefined) {
                    console.error('Conflicting rules for flex specified.');
                }
            }

            const flexValue = def.flex;
            delete adaptedRuleSet.flex;
            if (flexValue > 0) {
                // p 1 auto
                adaptedRuleSet.flexGrow = flexValue;
                adaptedRuleSet.flexShrink = 1;
            } else if (flexValue < 0) {
                // 0 -n auto
                adaptedRuleSet.flexGrow = 0;
                adaptedRuleSet.flexShrink = -flexValue;
            } else {
                // 0 0 auto
                adaptedRuleSet.flexGrow = 0;
                adaptedRuleSet.flexShrink = 0;
            }
        }

        if (cacheStyle) {
            return RN.StyleSheet.create({ _style: adaptedRuleSet })._style;
        }

        return AppConfig.isDevelopmentMode() ? Object.freeze(adaptedRuleSet) : adaptedRuleSet;
    }