File tree 6 files changed +70
-1
lines changed
6 files changed +70
-1
lines changed Original file line number Diff line number Diff line change
1
+ [ @vkruglikov/react-telegram-web-app ] ( ../README.md ) / SettingsButtonProps
2
+
3
+ # Interface: SettingsButtonProps
4
+
5
+ The props type of [ ` SettingsButton ` ] ( ../README.md#settingsbutton ) .
6
+
7
+ ## Table of contents
8
+
9
+ ### Properties
10
+
11
+ - [ onClick] ( SettingsButtonProps.md#onclick )
12
+
13
+ ## Properties
14
+
15
+ ### onClick
16
+
17
+ • ` Optional ` ** onClick** : () => ` void `
18
+
19
+ #### Type declaration
20
+
21
+ ▸ (): ` void `
22
+
23
+ The settings button press event handler
24
+
25
+ ##### Returns
26
+
27
+ ` void `
Original file line number Diff line number Diff line change
1
+ import { useContext , useEffect , useId } from 'react' ;
2
+ import { useWebApp , useSmoothButtonsTransition , systemContext } from './core' ;
3
+
4
+ export interface SettingsButtonProps {
5
+ onClick ?: ( ) => void ;
6
+ }
7
+
8
+ const SettingsButton = ( { onClick } : SettingsButtonProps ) : null => {
9
+ const system = useContext ( systemContext ) ;
10
+ const buttonId = useId ( ) ;
11
+ const WebApp = useWebApp ( ) ;
12
+
13
+ useEffect ( ( ) => {
14
+ if ( ! onClick || ! WebApp ?. SettingsButton ) {
15
+ return ;
16
+ }
17
+
18
+ WebApp . SettingsButton . onClick ( onClick ) ;
19
+ return ( ) => {
20
+ WebApp . SettingsButton . offClick ( onClick ) ;
21
+ } ;
22
+ } , [ onClick , WebApp ] ) ;
23
+
24
+ useSmoothButtonsTransition ( {
25
+ show : WebApp ?. SettingsButton ?. show ,
26
+ hide : WebApp ?. SettingsButton ?. hide ,
27
+ currentShowedIdRef : system . SettingsButton ,
28
+ id : buttonId ,
29
+ } ) ;
30
+
31
+ return null ;
32
+ } ;
33
+
34
+ export default SettingsButton ;
Original file line number Diff line number Diff line change @@ -62,6 +62,7 @@ const WebAppProvider = ({
62
62
const forceHideButtons = ( ) => {
63
63
globalWebApp ?. MainButton ?. hide ( ) ;
64
64
globalWebApp ?. BackButton ?. hide ( ) ;
65
+ globalWebApp ?. SettingsButton ?. hide ( ) ;
65
66
} ;
66
67
67
68
window . addEventListener ( 'beforeunload' , forceHideButtons ) ;
Original file line number Diff line number Diff line change @@ -38,11 +38,13 @@ export const optionsContext = createContext<Options>(DEFAULT_OPTIONS);
38
38
type SystemContext = {
39
39
MainButton : MutableRefObject < null | string > ;
40
40
BackButton : MutableRefObject < null | string > ;
41
+ SettingsButton : MutableRefObject < null | string > ;
41
42
} ;
42
43
43
44
export const createSystemContextValue = ( ) => ( {
44
45
MainButton : { current : null } ,
45
46
BackButton : { current : null } ,
47
+ SettingsButton : { current : null } ,
46
48
} ) ;
47
49
48
50
export const systemContext = createContext < SystemContext > (
Original file line number Diff line number Diff line change 1
1
export { default as MainButton , MainButtonProps } from './MainButton' ;
2
2
export { default as BackButton , BackButtonProps } from './BackButton' ;
3
+ export {
4
+ default as SettingsButton ,
5
+ SettingsButtonProps ,
6
+ } from './SettingsButton' ;
3
7
export {
4
8
default as useShowPopup ,
5
9
ShowPopupFunction ,
Original file line number Diff line number Diff line change @@ -21,7 +21,8 @@ export type WebAppUser = {
21
21
last_name ?: string ;
22
22
username ?: string ;
23
23
language_code ?: string ;
24
- photo_url ?: true ;
24
+ photo_url ?: string ;
25
+ is_premium ?: boolean ;
25
26
added_to_attachment_menu ?: true ;
26
27
allows_write_to_pm ?: true ;
27
28
} ;
You can’t perform that action at this time.
0 commit comments