Skip to content

Commit

Permalink
feat: add defaultViewProps prop
Browse files Browse the repository at this point in the history
  • Loading branch information
jsamr committed Jun 4, 2021
1 parent 7f64d48 commit ce49232
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/render-html/src/RenderHTML.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type RenderHTMLPropTypes = Record<keyof RenderHTMLProps, any>;
const propTypes: RenderHTMLPropTypes = {
renderers: PropTypes.object.isRequired,
defaultTextProps: PropTypes.object,
defaultViewProps: PropTypes.object,
source: PropTypes.oneOfType([
PropTypes.shape({
html: PropTypes.string.isRequired,
Expand Down
4 changes: 3 additions & 1 deletion packages/render-html/src/TBlockRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import mergeCollapsedMargins from './helpers/mergeCollapsedMargins';
import GenericPressable from './GenericPressable';
import { useRendererConfig } from './context/RenderRegistryProvider';
import { useDefaultViewProps } from './context/SharedPropsContext';

export const TDefaultBlockRenderer: TDefaultRenderer<TBlock> = ({
tnode,
Expand Down Expand Up @@ -52,15 +53,16 @@ const TBlockRenderer = ({
collapsedMarginTop
}: TNodeGenericRendererProps<TBlock>) => {
const { Default, Custom } = useRendererConfig(tnode);
const viewProps = useDefaultViewProps();
const commonProps: CustomTagRendererProps<TBlock> = {
key,
tnode,
style: mergeCollapsedMargins(collapsedMarginTop, {
...tnode.styles.nativeBlockFlow,
...tnode.styles.nativeBlockRet
}),
viewProps,
textProps: {},
viewProps: {},
type: 'text',
hasAnchorAncestor,
TDefaultRenderer: TDefaultBlockRenderer,
Expand Down
4 changes: 4 additions & 0 deletions packages/render-html/src/context/SharedPropsContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export function useDefaultTextProps(): TextProps {
return useSharedProps().defaultTextProps;
}

export function useDefaultViewProps(): TextProps {
return useSharedProps().defaultViewProps;
}

export function useComputeMaxWidthForTag(tagName: string) {
const { computeEmbeddedMaxWidth } = useSharedProps();
return useCallback(
Expand Down
6 changes: 6 additions & 0 deletions packages/render-html/src/shared-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ export interface RenderHTMLPassedProps<P = any> {
* @remarks "style" will be ignored. Use `baseStyle` instead.
*/
defaultTextProps?: Omit<TextProps, 'style'>;
/**
* Default props for View elements in the render tree.
*
* @remarks "style" will be ignored. Use `baseStyle` instead.
*/
defaultViewProps?: Omit<ViewProps, 'style'>;
/**
* Default props for WebView elements in the render tree used by plugins.
*/
Expand Down

0 comments on commit ce49232

Please sign in to comment.