Skip to content

Commit 86a51b3

Browse files
authored
Feat/ Add custom content to Hint (#1302)
* Feat/ Add custom content to Hint * fix pressing issue with Android
1 parent 5090482 commit 86a51b3

File tree

3 files changed

+148
-106
lines changed

3 files changed

+148
-106
lines changed

demo/src/screens/componentScreens/HintsScreen.tsx

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import React, {Component} from 'react';
2+
import {Alert} from 'react-native';
23
import {View, Text, Hint, Button, RadioGroup, RadioButton, Switch} from 'react-native-ui-lib'; //eslint-disable-line
34

45
const settingsIcon = require('../../assets/icons/settings.png');
56

67
type HintScreenProps = {};
78
type HintScreenState = {
8-
showHint: boolean,
9-
useShortMessage: boolean,
10-
showBottomHint: boolean,
11-
showIcon: boolean,
12-
targetPosition: string,
13-
useTargetFrame?: boolean,
14-
useSideTip?: boolean
9+
showHint: boolean;
10+
useShortMessage: boolean;
11+
showBottomHint: boolean;
12+
showIcon: boolean;
13+
targetPosition: string;
14+
useTargetFrame?: boolean;
15+
useSideTip?: boolean;
16+
showCustomContent?: boolean;
1517
};
1618

1719
export default class HintsScreen extends Component<HintScreenProps, HintScreenState> {
@@ -24,7 +26,8 @@ export default class HintsScreen extends Component<HintScreenProps, HintScreenSt
2426
showIcon: false,
2527
targetPosition: 'flex-start',
2628
// useTargetFrame: true,
27-
useSideTip: false
29+
useSideTip: false,
30+
showCustomContent: false
2831
};
2932
}
3033

@@ -44,7 +47,8 @@ export default class HintsScreen extends Component<HintScreenProps, HintScreenSt
4447
targetPosition,
4548
useShortMessage,
4649
useSideTip,
47-
useTargetFrame
50+
useTargetFrame,
51+
showCustomContent
4852
} = this.state;
4953
const targetFrame = {x: 140, y: 100, width: 10, height: 10};
5054
const message = useShortMessage
@@ -56,7 +60,7 @@ export default class HintsScreen extends Component<HintScreenProps, HintScreenSt
5660
<View
5761
flex
5862
padding-20
59-
paddingT-120
63+
paddingT-100
6064
bg-dark80
6165
style={{zIndex: 10}}
6266
key={useTargetFrame ? 'withTargetFrame' : 'withElement'}
@@ -85,6 +89,17 @@ export default class HintsScreen extends Component<HintScreenProps, HintScreenSt
8589
// borderRadius={BorderRadiuses.br40}
8690
// edgeMargins={30}
8791
// onBackgroundPress={() => this.setState({showHint: !showHint})}
92+
customContent={
93+
showCustomContent ? (
94+
<Text text70 white>
95+
Click
96+
<Text onPress={() => Alert.alert('custom content :)')} text70BO red40>
97+
{' here '}
98+
</Text>
99+
for more information
100+
</Text>
101+
) : undefined
102+
}
88103
testID={'Hint'}
89104
>
90105
{!useTargetFrame && (
@@ -158,6 +173,11 @@ export default class HintsScreen extends Component<HintScreenProps, HintScreenSt
158173
<Switch value={useTargetFrame} onValueChange={value => this.setState({useTargetFrame: value})}/>
159174
<Text marginL-10>Use random position</Text>
160175
</View>
176+
177+
<View row centerV marginV-10>
178+
<Switch value={showCustomContent} onValueChange={value => this.setState({showCustomContent: value})}/>
179+
<Text marginL-10>Show custom content</Text>
180+
</View>
161181
</View>
162182
</View>
163183
);

generatedTypes/components/hint/index.d.ts

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,64 +32,68 @@ interface Paddings {
3232
}
3333
export interface HintProps {
3434
/**
35-
* Control the visibility of the hint
36-
*/
35+
* Control the visibility of the hint
36+
*/
3737
visible?: boolean;
3838
/**
39-
* The hint background color
40-
*/
39+
* The hint background color
40+
*/
4141
color?: string;
4242
/**
43-
* The hint message
44-
*/
43+
* The hint message
44+
*/
4545
message?: string | ReactElement;
4646
/**
47-
* The hint message custom style
48-
*/
47+
* The hint message custom style
48+
*/
4949
messageStyle?: StyleProp<TextStyle>;
5050
/**
51-
* Icon to show next to the hint's message
52-
*/
51+
* Icon to show next to the hint's message
52+
*/
5353
icon?: ImageSourcePropType;
5454
/**
55-
* The icon's style
56-
*/
55+
* The icon's style
56+
*/
5757
iconStyle?: StyleProp<ImageStyle>;
5858
/**
59-
* The hint's position
60-
*/
59+
* The hint's position
60+
*/
6161
position?: HintPositions;
6262
/**
63-
* Provide custom target position instead of wrapping a child
64-
*/
63+
* Provide custom target position instead of wrapping a child
64+
*/
6565
targetFrame?: HintTargetFrame;
6666
/**
67-
* Show side tips instead of the middle tip
68-
*/
67+
* Show side tips instead of the middle tip
68+
*/
6969
useSideTip?: boolean;
7070
/**
71-
* The hint's border radius
72-
*/
71+
* The hint's border radius
72+
*/
7373
borderRadius?: number;
7474
/**
75-
* Hint margins from screen edges
76-
*/
75+
* Hint margins from screen edges
76+
*/
7777
edgeMargins?: number;
7878
/**
79-
* Hint offset from target
80-
*/
79+
* Hint offset from target
80+
*/
8181
offset?: number;
8282
/**
83-
* Callback for the background press
84-
*/
83+
* Callback for the background press
84+
*/
8585
onBackgroundPress?: (event: GestureResponderEvent) => void;
8686
/**
87-
* The hint container width
88-
*/
87+
* The hint container width
88+
*/
8989
containerWidth?: number;
9090
/**
91-
* The hint's test identifier
92-
*/
91+
* Custom content element to render inside the hint container
92+
*/
93+
customContent?: JSX.Element;
94+
/**
95+
* The hint's test identifier
96+
*/
9397
testID?: string;
9498
/**
9599
* Additional styling
@@ -152,6 +156,7 @@ declare class Hint extends Component<HintProps, HintState> {
152156
};
153157
getTipPosition(): Position;
154158
renderHintTip(): JSX.Element;
159+
renderContent(): JSX.Element;
155160
renderHint(): JSX.Element | undefined;
156161
renderHintContainer(): JSX.Element;
157162
renderChildren(): React.ReactElement<any, string | ((props: any) => React.ReactElement<any, any> | null) | (new (props: any) => React.Component<any, any, any>)> | undefined;

0 commit comments

Comments
 (0)