Skip to content

Commit 883f5d3

Browse files
authored
Feat/hint add props (#1399)
* Hint - add 'enableShadow' and 'removePaddings'; Adding reactions strip to demo. * Adding elevation for Android * improving example * Removing white bg restriction for shadow * improving example screen
1 parent 1648808 commit 883f5d3

File tree

3 files changed

+118
-25
lines changed

3 files changed

+118
-25
lines changed

demo/src/screens/componentScreens/HintsScreen.tsx

Lines changed: 61 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import _ from 'lodash';
12
import React, {Component} from 'react';
23
import {Alert} from 'react-native';
3-
import {View, Text, Hint, Button, RadioGroup, RadioButton, Switch} from 'react-native-ui-lib'; //eslint-disable-line
4+
import {Colors, View, Text, Hint, Button, RadioGroup, RadioButton, Switch} from 'react-native-ui-lib';
5+
46

57
const settingsIcon = require('../../assets/icons/settings.png');
8+
const reactions = ['❤️', '😮', '😔', '😂', '😡'];
69

710
type HintScreenProps = {};
811
type HintScreenState = {
@@ -14,11 +17,14 @@ type HintScreenState = {
1417
useTargetFrame?: boolean;
1518
useSideTip?: boolean;
1619
showCustomContent?: boolean;
20+
showReactionStrip?: boolean;
21+
enableShadow?: boolean
1722
};
1823

1924
export default class HintsScreen extends Component<HintScreenProps, HintScreenState> {
2025
constructor(props: HintScreenProps) {
2126
super(props);
27+
2228
this.state = {
2329
showHint: true,
2430
useShortMessage: false,
@@ -27,20 +33,46 @@ export default class HintsScreen extends Component<HintScreenProps, HintScreenSt
2733
targetPosition: 'flex-start',
2834
// useTargetFrame: true,
2935
useSideTip: false,
30-
showCustomContent: false
36+
showCustomContent: false,
37+
showReactionStrip: false,
38+
enableShadow: false
3139
};
3240
}
3341

34-
componentDidMount() {}
35-
3642
toggleHintPosition = () => {
3743
this.setState({
3844
showBottomHint: !this.state.showBottomHint
3945
});
4046
};
4147

4248
onHintPressed = () => {
43-
alert('Hint Pressed');
49+
Alert.alert('Hint Pressed');
50+
}
51+
52+
onReactionPress = () => {
53+
Alert.alert('Reaction button pressed');
54+
}
55+
56+
renderCustomContent() {
57+
return (
58+
<Text text70 white>
59+
Click
60+
<Text onPress={() => Alert.alert('custom content :)')} text70BO red40>
61+
{' here '}
62+
</Text>
63+
for more information
64+
</Text>
65+
);
66+
}
67+
68+
renderReactionStrip() {
69+
return (
70+
<View row padding-8>
71+
{_.map(reactions, (item, index) => (
72+
<Button round link key={index} label={item} onPress={this.onReactionPress}/>
73+
))}
74+
</View>
75+
);
4476
}
4577

4678
render() {
@@ -52,12 +84,14 @@ export default class HintsScreen extends Component<HintScreenProps, HintScreenSt
5284
useShortMessage,
5385
useSideTip,
5486
useTargetFrame,
55-
showCustomContent
87+
showCustomContent,
88+
showReactionStrip,
89+
enableShadow
5690
} = this.state;
5791
const targetFrame = {x: 140, y: 100, width: 10, height: 10};
58-
const message = useShortMessage
59-
? 'Add other cool and useful stuff.'
60-
: 'Add other cool and useful stuff through adding apps to your visitors to enjoy.';
92+
const message = useShortMessage ?
93+
'Add other cool and useful stuff.' :
94+
'Add other cool and useful stuff through adding apps to your visitors to enjoy.';
6195

6296
return (
6397
<View flex>
@@ -95,16 +129,12 @@ export default class HintsScreen extends Component<HintScreenProps, HintScreenSt
95129
// edgeMargins={30}
96130
// onBackgroundPress={() => this.setState({showHint: !showHint})}
97131
customContent={
98-
showCustomContent ? (
99-
<Text text70 white>
100-
Click
101-
<Text onPress={() => Alert.alert('custom content :)')} text70BO red40>
102-
{' here '}
103-
</Text>
104-
for more information
105-
</Text>
106-
) : undefined
132+
showCustomContent ?
133+
this.renderCustomContent() : showReactionStrip ? this.renderReactionStrip() : undefined
107134
}
135+
color={!showCustomContent && showReactionStrip ? Colors.white : undefined}
136+
removePaddings={!showCustomContent && showReactionStrip}
137+
enableShadow={enableShadow}
108138
testID={'Hint'}
109139
>
110140
{!useTargetFrame && (
@@ -174,6 +204,11 @@ export default class HintsScreen extends Component<HintScreenProps, HintScreenSt
174204
<Text marginL-10>Toggle Icon</Text>
175205
</View>
176206

207+
<View row centerV marginV-10>
208+
<Switch value={enableShadow} onValueChange={value => this.setState({enableShadow: value})}/>
209+
<Text marginL-10>Toggle shadow</Text>
210+
</View>
211+
177212
<View row centerV marginV-10>
178213
<Switch value={useTargetFrame} onValueChange={value => this.setState({useTargetFrame: value})}/>
179214
<Text marginL-10>Use random position</Text>
@@ -183,6 +218,14 @@ export default class HintsScreen extends Component<HintScreenProps, HintScreenSt
183218
<Switch value={showCustomContent} onValueChange={value => this.setState({showCustomContent: value})}/>
184219
<Text marginL-10>Show custom content</Text>
185220
</View>
221+
222+
<View row centerV marginV-10>
223+
<Switch
224+
value={showReactionStrip}
225+
onValueChange={value => this.setState({showReactionStrip: value, enableShadow: true})}
226+
/>
227+
<Text marginL-10>Show reaction strip</Text>
228+
</View>
186229
</View>
187230
</View>
188231
);

generatedTypes/components/hint/index.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ export interface HintProps {
9595
* Custom content element to render inside the hint container
9696
*/
9797
customContent?: JSX.Element;
98+
/**
99+
* Remove all hint's paddings
100+
*/
101+
removePaddings?: boolean;
102+
/**
103+
* Enable shadow (for hint with white background only)
104+
*/
105+
enableShadow?: boolean;
98106
/**
99107
* The hint's test identifier
100108
*/
@@ -165,6 +173,7 @@ declare class Hint extends Component<HintProps, HintState> {
165173
}[];
166174
};
167175
getTipPosition(): Position;
176+
shouldEnableShadow(): boolean | undefined;
168177
renderHintTip(): JSX.Element;
169178
renderContent(): JSX.Element;
170179
renderHint(): JSX.Element | undefined;

src/components/hint/index.tsx

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export interface HintProps {
124124
/**
125125
* Callback for the background press
126126
*/
127-
onBackgroundPress?: (event: GestureResponderEvent) => void;
127+
onBackgroundPress?: (event: GestureResponderEvent) => void;
128128
/**
129129
* The hint container width
130130
*/
@@ -133,6 +133,14 @@ export interface HintProps {
133133
* Custom content element to render inside the hint container
134134
*/
135135
customContent?: JSX.Element;
136+
/**
137+
* Remove all hint's paddings
138+
*/
139+
removePaddings?: boolean;
140+
/**
141+
* Enable shadow (for hint with white background only)
142+
*/
143+
enableShadow?: boolean;
136144
/**
137145
* The hint's test identifier
138146
*/
@@ -198,6 +206,7 @@ class Hint extends Component<HintProps, HintState> {
198206
const {message} = this.props;
199207
const targetRefTag = findNodeHandle(this.targetRef);
200208
const hintRefTag = findNodeHandle(this.hintRef);
209+
201210
if (targetRefTag && _.isString(message)) {
202211
AccessibilityInfo.setAccessibilityFocus(targetRefTag);
203212
} else if (hintRefTag) {
@@ -253,6 +262,7 @@ class Hint extends Component<HintProps, HintState> {
253262
if (targetFrame) {
254263
return targetFrame;
255264
}
265+
256266
return onBackgroundPress ? targetLayoutInWindow : targetLayout;
257267
}
258268

@@ -280,12 +290,14 @@ class Hint extends Component<HintProps, HintState> {
280290
if (!_.isUndefined(useSideTip)) {
281291
return useSideTip;
282292
}
293+
283294
return this.getTargetPositionOnScreen() !== TARGET_POSITIONS.CENTER;
284295
}
285296

286297
getTargetPositionOnScreen() {
287298
if (this.targetLayout?.x && this.targetLayout?.width) {
288299
const targetMidPosition = this.targetLayout.x + this.targetLayout.width / 2;
300+
289301
if (targetMidPosition > this.containerWidth * (2 / 3)) {
290302
return TARGET_POSITIONS.RIGHT;
291303
} else if (targetMidPosition < this.containerWidth * (1 / 3)) {
@@ -328,6 +340,7 @@ class Hint extends Component<HintProps, HintState> {
328340

329341
getHintPadding() {
330342
const paddings: Paddings = {paddingVertical: this.hintOffset, paddingHorizontal: this.edgeMargins};
343+
331344
if (this.useSideTip && this.targetLayout?.x) {
332345
const targetPositionOnScreen = this.getTargetPositionOnScreen();
333346
if (targetPositionOnScreen === TARGET_POSITIONS.LEFT) {
@@ -336,12 +349,14 @@ class Hint extends Component<HintProps, HintState> {
336349
paddings.paddingRight = this.containerWidth - this.targetLayout.x - this.targetLayout.width;
337350
}
338351
}
352+
339353
return paddings;
340354
}
341355

342356
getHintAnimatedStyle = () => {
343357
const {position} = this.props;
344358
const translateY = position === HintPositions.TOP ? -10 : 10;
359+
345360
return {
346361
opacity: this.visibleAnimated,
347362
transform: [
@@ -437,14 +452,31 @@ class Hint extends Component<HintProps, HintState> {
437452
}
438453

439454
renderContent() {
440-
const {message, messageStyle, icon, iconStyle, borderRadius, color, customContent, testID} = this.props;
455+
const {
456+
message,
457+
messageStyle,
458+
icon,
459+
iconStyle,
460+
borderRadius,
461+
color,
462+
customContent,
463+
removePaddings,
464+
enableShadow,
465+
testID
466+
} = this.props;
441467

442468
return (
443469
<View
444470
testID={`${testID}.message`}
445471
row
446472
centerV
447-
style={[styles.hint, color && {backgroundColor: color}, !_.isUndefined(borderRadius) && {borderRadius}]}
473+
style={[
474+
styles.hint,
475+
!removePaddings && styles.hintPaddings,
476+
enableShadow && styles.containerShadow,
477+
color && {backgroundColor: color},
478+
!_.isUndefined(borderRadius) && {borderRadius}
479+
]}
448480
ref={this.setHintRef}
449481
>
450482
{customContent}
@@ -511,6 +543,7 @@ class Hint extends Component<HintProps, HintState> {
511543

512544
render() {
513545
const {onBackgroundPress, testID} = this.props;
546+
514547
if (!this.props.visible && this.state.hintUnmounted) {
515548
return this.props.children;
516549
}
@@ -541,7 +574,6 @@ class Hint extends Component<HintProps, HintState> {
541574
const styles = StyleSheet.create({
542575
container: {
543576
position: 'absolute'
544-
545577
},
546578
// overlay: {
547579
// position: 'absolute',
@@ -556,11 +588,20 @@ const styles = StyleSheet.create({
556588
},
557589
hint: {
558590
maxWidth: 400,
559-
backgroundColor: DEFAULT_COLOR,
591+
borderRadius: BorderRadiuses.br60,
592+
backgroundColor: DEFAULT_COLOR
593+
},
594+
hintPaddings: {
560595
paddingHorizontal: Spacings.s5,
561596
paddingTop: Spacings.s3,
562-
paddingBottom: Spacings.s4,
563-
borderRadius: BorderRadiuses.br60
597+
paddingBottom: Spacings.s4
598+
},
599+
containerShadow: {
600+
shadowColor: Colors.dark40,
601+
shadowOpacity: 0.25,
602+
shadowRadius: 5,
603+
shadowOffset: {height: 5, width: 0},
604+
elevation: 2
564605
},
565606
hintMessage: {
566607
...Typography.text70,

0 commit comments

Comments
 (0)