1+ import React , { Component } from 'react' ;
2+ import { Alert } from 'react-native' ;
3+ import {
4+ Usercentrics ,
5+ UsercentricsLoggerLevel ,
6+ UsercentricsOptions ,
7+ UsercentricsServiceConsent ,
8+ UsercentricsUIOptions ,
9+ } from '../../../src/index' ;
10+
11+ interface Props {
12+ children : Element ;
13+ }
14+
15+ interface State {
16+ consents : [ UsercentricsServiceConsent ] | null ;
17+ ucReset : ( ) => void ;
18+ }
19+
20+ export const ConsentContext = React . createContext < [ UsercentricsServiceConsent ] | null > ( null ) ;
21+ export const DevelopemetConsentContext = React . createContext < null | ( ( ) => void ) > ( null ) ;
22+
23+ class Consent extends Component < Props , State > {
24+ constructor ( props : any ) {
25+ super ( props ) ;
26+ const options = new UsercentricsOptions ( "Yi9N3aXia" ) ;
27+ // if (Config.EXPERIMENTAL_FEATURES) {
28+ options . loggerLevel = UsercentricsLoggerLevel . debug ;
29+ // }
30+ // options.defaultLanguage = this.props.intl.locale;
31+ Usercentrics . configure ( options ) ;
32+ this . state = { consents : null , ucReset : Usercentrics . reset } ;
33+ }
34+
35+ async componentDidMount ( ) {
36+ const status = await Usercentrics . status ( ) ;
37+ const mapped = status . consents . map ( consent => { return consent . templateId } ) ;
38+
39+ Alert . alert ( "Component Did Mount" , `status ${ status . shouldShowCMP } , consents: ${ mapped } ` )
40+
41+ if ( status . shouldShowCMP ) {
42+ this . showCMP ( false ) . then ( ) ;
43+ } else {
44+ this . applyConsents ( status . consents ) ;
45+ }
46+ }
47+
48+ async showCMP ( showCloseButton : boolean ) {
49+ const options = new UsercentricsUIOptions ( showCloseButton ) ;
50+ const response = await Usercentrics . showCMP ( options ) ;
51+ console . log ( 'showCMP' , response . consents ) ;
52+ this . setState ( { consents : response . consents } ) ;
53+ }
54+
55+ applyConsents ( consents : [ UsercentricsServiceConsent ] ) {
56+ console . log ( 'applyConsents' , consents ) ;
57+ this . setState ( { consents } ) ;
58+ }
59+
60+ render ( ) {
61+ return (
62+ < ConsentContext . Provider value = { this . state . consents } >
63+ { /* {Config.EXPERIMENTAL_FEATURES ? ( */ }
64+ < DevelopemetConsentContext . Provider value = { this . state . ucReset } >
65+ { this . props . children }
66+ </ DevelopemetConsentContext . Provider >
67+ { /* ) : (
68+ this.props.children
69+ )} */ }
70+ </ ConsentContext . Provider >
71+ ) ;
72+ }
73+ }
74+
75+ export default Consent ;
0 commit comments