-
Notifications
You must be signed in to change notification settings - Fork 819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add possibility to add multiple shadows and shadow spread #277
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import PropTypes from 'prop-types'; | ||
|
||
module.exports = { | ||
shadowColor: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), | ||
shadowOffset: { width: PropTypes.number, height: PropTypes.number }, | ||
shadowSpread: PropTypes.number, | ||
shadowOpacity: PropTypes.number, | ||
shadowRadius: PropTypes.number, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import PropTypes from 'prop-types'; | |
import StyleSheet from '../stylesheet'; | ||
import ViewStylePropTypes from './ViewStylePropTypes'; | ||
import ResizingConstraintPropTypes from './ResizingConstraintPropTypes'; | ||
import ShadowGroupPropTypes from './ShadowGroupPropTypes'; | ||
|
||
const propTypes = { | ||
// TODO(lmr): do some nice warning stuff like RN does | ||
|
@@ -18,6 +19,11 @@ const propTypes = { | |
resizingConstraint: PropTypes.shape({ | ||
...ResizingConstraintPropTypes, | ||
}), | ||
shadowGroup: PropTypes.arrayOf( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's just call it |
||
PropTypes.shape({ | ||
...ShadowGroupPropTypes, | ||
}) | ||
), | ||
children: PropTypes.node, | ||
}; | ||
|
||
|
@@ -33,6 +39,7 @@ class View extends React.Component { | |
name={this.props.name} | ||
style={StyleSheet.flatten(this.props.style)} | ||
resizingConstraint={this.props.resizingConstraint} | ||
shadowGroup={this.props.shadowGroup} | ||
> | ||
{this.props.children} | ||
</view> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import type { SJFill, SJPath, SJRect, SJShapeGroupLayer } from '@skpm/sketchapp-json-flow-types'; | ||
import { makeResizeConstraint } from './hacksForJSONImpl'; | ||
import { generateID, makeRect } from './models'; | ||
import type { ResizeConstraints } from '../types'; | ||
import type { ResizeConstraints, SketchShadowGroup } from '../types'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. used anywhere? |
||
|
||
type Radii = Array<number>; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,13 @@ import type { SJShapeGroupLayer } from '@skpm/sketchapp-json-flow-types'; | |
import SketchRenderer from './SketchRenderer'; | ||
import { makeRect, makeColorFill, makeColorFromCSS } from '../jsonUtils/models'; | ||
import { makeRectShapeLayer, makeShapeGroup } from '../jsonUtils/shapeLayers'; | ||
import type { ViewStyle, LayoutInfo, TextStyle } from '../types'; | ||
import type { | ||
ViewStyle, | ||
LayoutInfo, | ||
TextStyle, | ||
SketchShadowGroup, | ||
ResizeConstraints, | ||
} from '../types'; | ||
import { | ||
makeBorderOptions, | ||
makeShadow, | ||
|
@@ -24,6 +30,7 @@ const VISIBLE_STYLES = [ | |
'shadowOffset', | ||
'shadowOpacity', | ||
'shadowRadius', | ||
'shadowSpread', | ||
'backgroundColor', | ||
'borderColor', | ||
'borderTopColor', | ||
|
@@ -55,7 +62,7 @@ class ViewRenderer extends SketchRenderer { | |
style: ViewStyle, | ||
textStyle: TextStyle, | ||
// eslint-disable-next-line no-unused-vars | ||
props: any, | ||
props: any | ||
): Array<SJShapeGroupLayer> { | ||
const layers = []; | ||
// NOTE(lmr): the group handles the position, so we just care about width/height here | ||
|
@@ -106,7 +113,13 @@ class ViewRenderer extends SketchRenderer { | |
const fill = makeColorFill(backgroundColor); | ||
const content = makeShapeGroup(frame, [shapeLayer], [fill]); | ||
|
||
if (hasAnyDefined(style, SHADOW_STYLES)) { | ||
if (props.shadowGroup) { | ||
const shadows = []; | ||
props.shadowGroup.map(shadowStyle => | ||
shadows.push(makeShadow(shadowStyle)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's push to |
||
); | ||
content.style.shadows = shadows; | ||
} else if (hasAnyDefined(style, SHADOW_STYLES)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of an |
||
const shadow = [makeShadow(style)]; | ||
if (style.shadowInner) { | ||
content.style.innerShadows = shadow; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,8 @@ export type ViewStyle = { | |
shadowOffset: { width: number, height: number }, | ||
shadowOpacity: number, | ||
shadowRadius: number, | ||
shadowSpread: number, | ||
shadowInner: "innerShadow" | "shadow", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be a And we could probably reuse the |
||
width: number, | ||
height: number, | ||
top: number, | ||
|
@@ -180,3 +182,13 @@ export type ResizeConstraints = { | |
fixedHeight: boolean, | ||
fixedWidth: boolean, | ||
}; | ||
|
||
export type SketchShadow = { | ||
shadowColor: Color, | ||
shadowOffset: { width: number, height: number }, | ||
shadowSpread: number, | ||
shadowOpacity: number, | ||
shadowRadius: number | ||
}; | ||
|
||
export type SketchShadowGroup = Array<SketchShadow>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should add
shadowInner
to support multiple inner shadows as well