Skip to content

Instantly share code, notes, and snippets.

@mattpodwysocki
Created August 9, 2016 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattpodwysocki/ae2e9fa50614b22c37a26edc27ce179e to your computer and use it in GitHub Desktop.
Save mattpodwysocki/ae2e9fa50614b22c37a26edc27ce179e to your computer and use it in GitHub Desktop.
using ReactNative.UIManager;
using System.Threading;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace ReactNative.Views.TextInput
{
class ReactPasswordBox : PasswordBox
{
private int _eventCount;
public ReactPasswordBox()
{
SizeChanged += OnSizeChanged;
}
public int CurrentEventCount
{
get
{
return _eventCount;
}
}
public bool ClearTextOnFocus
{
get;
set;
}
public bool SelectTextOnFocus
{
get;
set;
}
public int IncrementEventCount()
{
return Interlocked.Increment(ref _eventCount);
}
protected override void OnGotFocus(RoutedEventArgs e)
{
base.OnGotFocus(e);
if (ClearTextOnFocus)
{
Text = "";
}
if (SelectTextOnFocus)
{
SelectionStart = 0;
SelectionLength = Text.Length;
}
}
private void OnSizeChanged(object sender, SizeChangedEventArgs e)
{
this.GetReactContext()
.GetNativeModule<UIManagerModule>()
.EventDispatcher
.DispatchEvent(
new ReactTextChangedEvent(
this.GetTag(),
Text,
e.NewSize.Width,
e.NewSize.Height,
IncrementEventCount()));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment