Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
refresh() {
Log.D(`refresh()`);
if (!this.nativeView) {
return;
}
let itemsCount = this.getItemCount();
Log.D(`Items count: `, itemsCount);
if(isNullOrUndefined(itemsCount)){
return;
}
// Using 'items' property and 'itemTemplate' to populate Carousel. Remove all parent children first then add all items.
if (!isNullOrUndefined(this.itemTemplate)) {
Log.D(`Using template mode`);
this.removeChildren();
for (let i = 0; i < itemsCount; i++) {
const viewToAdd = !isNullOrUndefined(this.itemTemplate) ? parse(this.itemTemplate, this) : this._getDefaultItemContent(i);
const dataItem = this._getDataItem(i);
viewToAdd.bindingContext = dataItem;
this.addChild(viewToAdd);
}
}
// Notify adapter and indicatorView that items have changed.
var _this = this;
this.logMsg("activity: " + this.Config.activity, SocialLogin_common_1.LOGTAG_INIT_ENV);
if (types_1.isNullOrUndefined(this.Config.activity)) {
this.Config.activity = application_1.android.foregroundActivity || application_1.android.startActivity;
}
// Google
if (this.Config.google.initialize) {
result = this.initGoogle(result);
}
// Facebook
if (this.Config.facebook.initialize) {
result = this.initFacebook(result);
}
// Twitter
if (!types_1.isNullOrUndefined(this.Config.twitter.key) &&
!types_1.isNullOrUndefined(this.Config.twitter.secret)) {
result = this.initTwitter(result);
}
if (!types_1.isNullOrUndefined(this.Config.activity)) {
var onLoginResult_1 = function (_a) {
var requestCode = _a.requestCode, resultCode = _a.resultCode, intent = _a.intent;
if (requestCode === _this._rcGoogleSignIn || requestCode === _this._rcFacebookSignIn) {
var resultCtx = {};
var callback = _this._loginCallback;
var activityResultHandled = false;
try {
if (requestCode === _this._rcGoogleSignIn) {
resultCtx.provider = "google";
activityResultHandled = true;
if (resultCode === android.app.Activity.RESULT_OK) {
_this.logMsg("OK", LOGTAG_ON_ACTIVITY_RESULT);
var signInResult = com.google.android.gms.auth.api.Auth.GoogleSignInApi.getSignInResultFromIntent(intent);
refresh() {
Log.D(`refresh()`);
if (!this.isLoaded || !this.nativeView) {
this._isDirty = true;
return;
}
this._isDirty = false;
this.nativeView.setItems(NSMutableArray.new());
if (isNullOrUndefined(this.itemTemplate)) {
Log.D(`Using generic-mode`);
const nsArray = NSMutableArray.new();
Log.D(`children count: `, this.getChildrenCount());
this.eachChildView(staticView => {
if (staticView instanceof CarouselItem) {
staticView.width = this.width;
staticView.height = this.height;
const dkCarouselViewItem1 = new DKCarouselViewItem();
dkCarouselViewItem1.view = staticView.ios;
nsArray.addObject(dkCarouselViewItem1);
}
return true;
});
this.nativeView.setItems(nsArray);
Log.D(`items set: `, nsArray.count);
}
addDatabaseChangeListener(callback: any) {
const token = this.ios.addChangeListener((change: any) => {
if (callback && typeof callback === 'function') {
const ids = [];
const documentIds = change.documentIDs;
const size = documentIds.count;
for (let i = 0; i < size; i++) {
const item = documentIds[i];
ids.push(item);
}
callback(ids);
}
});
if (!types.isNullOrUndefined(token)) {
this._listenerMap[callback] = token;
}
}
getItemCount() {
let result;
if (isNullOrUndefined(this.owner.get().items) || !isNumber(this.owner.get().items.length)) {
result = this.owner ? this.owner.get()._childrenCount : 0;
} else {
result = this.owner ? this.owner.get().items.length : 0;
}
CLog(CLogTypes.info, `CardStackAdapter getCount result = ${result}`);
return result;
}
}
private deserialize(data: any) {
if (typeof data === 'string' || typeof data === 'number' || typeof data === 'boolean' || typeof data !== 'object') return data;
if (types.isNullOrUndefined(data)) {
return data;
}
if (data instanceof NSNull) {
return null;
}
if (data instanceof CBLDictionary) {
const keys = data.keys;
const length = keys.count;
const object = {};
for (let i = 0; i < length; i++) {
const key = keys.objectAtIndex(i);
const nativeItem = data.valueForKey(key);
object[key] = this.deserialize(nativeItem);
}
removeDatabaseChangeListener(callback: any) {
const token = this._listenerMap[callback];
if (!types.isNullOrUndefined(token)) {
this.android.removeChangeListener(token);
delete this._listenerMap[callback];
}
}
this.eachChildView(staticView => {
if (staticView instanceof CarouselItem) {
staticView.width = this.width;
staticView.height = this.height;
const dkCarouselViewItem1 = new DKCarouselViewItem();
dkCarouselViewItem1.view = staticView.ios;
nsArray.addObject(dkCarouselViewItem1);
}
return true;
});
this.nativeView.setItems(nsArray);
Log.D(`items set: `, nsArray.count);
}
else {
Log.D(`Using template-mode`);
if(isNullOrUndefined(this.items)){
Log.D(`Items list is null...`);
return;
}
this.removeChildren();
const nsArray = NSMutableArray.new();
const length = this.items.length;
Log.D(`items length: `, length);
for (let i = 0; i < length; i++) {
const viewToAdd = !isNullOrUndefined(this.itemTemplate) ? parse(this.itemTemplate, this) : null;
if (!viewToAdd) continue;
const dataItem = this._getDataItem(i);
viewToAdd.bindingContext = dataItem;
this.addChild(viewToAdd);
}