Skip to content

Commit

Permalink
Fix NVC for RCTTextInlineImage
Browse files Browse the repository at this point in the history
Summary:
This diff fixes the Static/Native ViewConfigs for RCTTextInlineImage.

Changelog: [Internal]

Reviewed By: p-sun, sshic

Differential Revision: D33674127

fbshipit-source-id: 8cf5ffeaca635b4afd30c437dc0f87ea1fdc15a8
  • Loading branch information
RSNara authored and facebook-github-bot committed Jan 20, 2022
1 parent 26d05d8 commit 0343e69
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 80 deletions.
23 changes: 16 additions & 7 deletions Libraries/Image/Image.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,22 @@ let Image = (props: ImagePropsType, forwardedRef) => {
: nativeProps;
return (
<TextAncestor.Consumer>
{hasTextAncestor =>
hasTextAncestor ? (
<TextInlineImageNativeComponent {...nativePropsWithAnalytics} />
) : (
<ImageViewNativeComponent {...nativePropsWithAnalytics} />
)
}
{hasTextAncestor => {
if (hasTextAncestor) {
let src = Array.isArray(sources) ? sources : [sources];
return (
<TextInlineImageNativeComponent
style={style}
resizeMode={props.resizeMode}
headers={nativeProps.headers}
src={src}
ref={forwardedRef}
/>
);
}

return <ImageViewNativeComponent {...nativePropsWithAnalytics} />;
}}
</TextAncestor.Consumer>
);
}}
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Image/ImageViewNativeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Props = $ReadOnly<{
// Android native props
shouldNotifyLoadEvents?: boolean,
src?: ?ResolvedAssetSource | $ReadOnlyArray<{uri: string, ...}>,
headers?: ?string,
headers?: ?{[string]: string},
defaultSrc?: ?string,
loadingIndicatorSrc?: ?string,
}>;
Expand Down
80 changes: 11 additions & 69 deletions Libraries/Image/TextInlineImageNativeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,90 +10,32 @@

'use strict';

import type {ResolvedAssetSource} from './AssetSourceResolver';
import type {HostComponent} from '../Renderer/shims/ReactNativeTypes';
import type {ImageProps} from './ImageProps';
import type {ViewProps} from '../Components/View/ViewPropTypes';
import type {ImageResizeMode} from './ImageResizeMode';
import * as NativeComponentRegistry from '../NativeComponent/NativeComponentRegistry';
import type {
ColorValue,
DangerouslyImpreciseStyle,
ImageStyleProp,
} from '../StyleSheet/StyleSheet';
import type {ColorValue} from '../StyleSheet/StyleSheet';

type Props = $ReadOnly<{
...ImageProps,
type NativeProps = $ReadOnly<{
...ViewProps,

style?: ImageStyleProp | DangerouslyImpreciseStyle,

// iOS native props
tintColor?: ColorValue,

// Android native props
shouldNotifyLoadEvents?: boolean,
src?: ?ResolvedAssetSource | $ReadOnlyArray<{uri: string, ...}>,
headers?: ?string,
defaultSrc?: ?string,
loadingIndicatorSrc?: ?string,
internal_analyticTag?: ?string,
resizeMode?: ?ImageResizeMode,
src?: ?$ReadOnlyArray<?$ReadOnly<{uri: string, ...}>>,
tintColor?: ?ColorValue,
headers?: ?{[string]: string},
}>;

const TextInlineImage: HostComponent<Props> =
NativeComponentRegistry.get<Props>('RCTTextInlineImage', () => ({
const TextInlineImage: HostComponent<NativeProps> =
NativeComponentRegistry.get<NativeProps>('RCTTextInlineImage', () => ({
uiViewClassName: 'RCTTextInlineImage',
bubblingEventTypes: {},
directEventTypes: {
topLoadStart: {
registrationName: 'onLoadStart',
},
topProgress: {
registrationName: 'onProgress',
},
topError: {
registrationName: 'onError',
},
topPartialLoad: {
registrationName: 'onPartialLoad',
},
topLoad: {
registrationName: 'onLoad',
},
topLoadEnd: {
registrationName: 'onLoadEnd',
},
},
directEventTypes: {},
validAttributes: {
blurRadius: true,
capInsets: {
diff: require('../Utilities/differ/insetsDiffer'),
},
defaultSource: {
process: require('./resolveAssetSource'),
},
defaultSrc: true,
fadeDuration: true,
headers: true,
internal_analyticTag: true,
loadingIndicatorSrc: true,
onError: true,
onLoad: true,
onLoadEnd: true,
onLoadStart: true,
onPartialLoad: true,
onProgress: true,
overlayColor: {
process: require('../StyleSheet/processColor'),
},
progressiveRenderingEnabled: true,
resizeMethod: true,
resizeMode: true,
shouldNotifyLoadEvents: true,
source: true,
src: true,
tintColor: {
process: require('../StyleSheet/processColor'),
},
headers: true,
},
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void setHeaders(ReadableMap headers) {
mHeaders = headers;
}

@ReactProp(name = "tintColor")
@ReactProp(name = "tintColor", customType = "Color")
public void setTintColor(int tintColor) {
mTintColor = tintColor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.controller.AbstractDraweeControllerBuilder;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.uimanager.BaseViewManager;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.ViewManager;

/**
* Manages Images embedded in Text nodes using Fresco. Since they are used only as a virtual nodes
* any type of native view operation will throw an {@link IllegalStateException}.
*/
@ReactModule(name = FrescoBasedReactTextInlineImageViewManager.REACT_CLASS)
public class FrescoBasedReactTextInlineImageViewManager
extends ViewManager<View, FrescoBasedReactTextInlineImageShadowNode> {
extends BaseViewManager<View, FrescoBasedReactTextInlineImageShadowNode> {

public static final String REACT_CLASS = "RCTTextInlineImage";

Expand Down

0 comments on commit 0343e69

Please sign in to comment.